:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #17202a;
  --muted: #5d6b7a;
  --border: #dde3e9;
  --primary: #1f6feb;
  --primary-text: #ffffff;
  --success: #1a7f4b;
  --success-bg: #e3f5ea;
  --danger: #c0362c;
  --danger-bg: #fbe7e5;
  --warn: #9a6200;
  --warn-bg: #fff3d6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --surface: #171e26;
    --surface-2: #1f2832;
    --text: #e6ebf0;
    --muted: #94a3b3;
    --border: #2b3642;
    --primary: #4b8ff5;
    --primary-text: #ffffff;
    --success: #4cc98a;
    --success-bg: #12301f;
    --danger: #f2756b;
    --danger-bg: #3a1714;
    --warn: #f0b84d;
    --warn-bg: #352708;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }

/* Botões e formulários */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: .6rem 1rem; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { padding: .35rem .65rem; font-size: .875rem; }
.btn-xl { padding: 1.1rem 1.5rem; font-size: 1.2rem; border-radius: 16px; width: 100%; }

label { display: block; font-size: .875rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; color: var(--text); font-size: 1rem; }
.check input { width: auto; }
.field { margin-bottom: .85rem; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; }
.hint { color: var(--muted); font-size: .875rem; }
.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-in { background: var(--success-bg); color: var(--success); }
.badge-out { background: var(--surface-2); color: var(--text); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }

/* ---------- Tela de ponto ---------- */
.punch { max-width: 480px; margin: 0 auto; min-height: 100dvh; padding: 16px; display: flex; flex-direction: column; }
.punch header { display: flex; justify-content: space-between; align-items: center; padding: 4px 0 12px; }
.punch header .company { font-weight: 700; }
.screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.25rem; text-align: center; }
.clock-time { font-size: clamp(3.5rem, 18vw, 5rem); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.clock-date { color: var(--muted); text-transform: capitalize; }
.cam { position: relative; width: min(78vw, 320px); aspect-ratio: 1; }
.cam video { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; transform: scaleX(-1); background: #000; }
.cam .ring { position: absolute; inset: -8px; border-radius: 50%; border: 6px solid var(--border); transition: border-color .2s; }
.cam .ring.ok { border-color: var(--success); }
.cam .ring.active { border-color: var(--primary); }
.cam .side { position: absolute; top: 50%; transform: translateY(-50%); font-size: 1.6rem; color: var(--border); transition: color .2s; }
.cam .side.left { left: -40px; }
.cam .side.right { right: -40px; }
.cam .side.done { color: var(--success); }
.status { font-size: 1.15rem; font-weight: 600; min-height: 3em; max-width: 340px; }
.photo-round { width: 132px; height: 132px; border-radius: 50%; object-fit: cover; transform: scaleX(-1); border: 4px solid var(--surface); box-shadow: var(--shadow); }
.punch-type { font-size: 1.6rem; font-weight: 800; text-transform: uppercase; }
.today { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; }
.stack { display: flex; flex-direction: column; gap: .6rem; width: 100%; }
.done-icon { width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; background: var(--success-bg); color: var(--success); }
.err-icon { background: var(--danger-bg); color: var(--danger); }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: .6rem .8rem; font-size: .9rem; }
.footer-link { text-align: center; font-size: .85rem; padding-top: 12px; }
.footer-link a { color: var(--muted); }

/* ---------- Painel do RH ---------- */
.admin-top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.admin-top .inner { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.admin-top h1 { font-size: 1.1rem; margin: 0; margin-right: auto; }
.tabs { display: flex; gap: 4px; overflow-x: auto; max-width: 100%; }
.tabs button { appearance: none; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: .5rem .8rem; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); }
.admin-main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: 1rem; }
.toolbar .field { margin: 0; min-width: 140px; flex: 1 1 140px; }
.toolbar .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.voided td { opacity: .5; text-decoration: line-through; }
tr.voided td.keep { text-decoration: none; }
tr.weekend td { background: var(--surface-2); }
tfoot td { font-weight: 700; }
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; cursor: zoom-in; transform: scaleX(-1); display: block; }
.pos { color: var(--success); }
.neg { color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

.emp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.emp { display: flex; gap: 12px; align-items: flex-start; }
.emp .avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; background: var(--surface-2); flex: none; display: grid; place-items: center; color: var(--muted); font-weight: 700; transform: scaleX(-1); }
.emp .avatar.initials { transform: none; }
.emp .info { flex: 1; min-width: 0; }
.emp .name { font-weight: 700; overflow-wrap: anywhere; }
.emp .meta { color: var(--muted); font-size: .85rem; }
.emp .btns { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 15, 20, .55); }
dialog .dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
dialog.wide { width: min(680px, calc(100vw - 32px)); }
dialog h4 { margin: 1.25rem 0 .25rem; font-size: 1rem; }
table.sched td, table.sched th { padding: .3rem .3rem; }
table.sched input { padding: .35rem .4rem; min-width: 92px; }
.loc { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: var(--surface-2); }
.loc .field { margin-bottom: .5rem; }
.loc-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.loc-actions [data-remove] { margin-left: auto; }
td.nowrap { white-space: nowrap; }
dialog.photo-view { width: auto; max-width: calc(100vw - 32px); padding: 8px; }
dialog.photo-view img { display: block; max-width: 100%; max-height: 80vh; border-radius: 8px; transform: scaleX(-1); }
.enroll-box { display: flex; flex-direction: column; align-items: center; gap: 1rem; text-align: center; padding: 12px 0; }
.enroll-box .cam { width: min(64vw, 260px); }

.login { max-width: 360px; margin: 10vh auto; padding: 16px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .7rem 1rem; border-radius: 10px; font-weight: 600; z-index: 50; max-width: calc(100vw - 32px); }

@media (max-width: 640px) {
  .hide-sm { display: none; }
}

@media print {
  .admin-top, .toolbar, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
