/* ===== Design tokens ===== */
:root{
  --bg:              #0d1117;
  --surface:         #161b22;
  --surface-2:       #1c2129;
  --surface-3:       #21262d;
  --border:          #30363d;
  --border-hover:    #484f58;
  --text:            #e6edf3;
  --text-muted:      #8b949e;
  --text-subtle:     #6e7681;
  --accent:          #2f81f7;
  --accent-hover:    #388bfd;
  --accent-soft:     #2f81f726;
  --success:         #3fb950;
  --success-soft:    #3fb95026;
  --danger:          #f85149;
  --danger-soft:     #f8514926;
  --warning:         #d29922;
  --warning-soft:    #d2992226;
  --radius-sm:       6px;
  --radius-md:       8px;
  --radius-lg:       12px;
  --sidebar-w:       248px;
  --topbar-h:        60px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%}
body{
  font-family:var(--font);
  background:var(--bg);
  color:var(--text);
  font-size:14px;
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
}
a{color:inherit;text-decoration:none;cursor:pointer}
svg{width:18px;height:18px;fill:currentColor;flex-shrink:0}
button{font-family:inherit}
code{font-family:Consolas,'SF Mono',monospace;background:var(--surface-3);padding:1px 6px;border-radius:4px;font-size:12px}
::selection{background:var(--accent-soft);color:var(--text)}

/* ===== Sidebar ===== */
.sidebar{
  position:fixed;top:0;left:0;bottom:0;width:var(--sidebar-w);
  background:var(--surface);border-right:1px solid var(--border);
  display:flex;flex-direction:column;z-index:100;
}
.brand{display:flex;align-items:center;gap:11px;padding:18px 20px;border-bottom:1px solid var(--border)}
.brand-mark{
  width:36px;height:36px;border-radius:10px;flex-shrink:0;
  background:linear-gradient(135deg,var(--accent),#8957e5);
  display:flex;align-items:center;justify-content:center;font-weight:800;font-size:14px;color:#fff;
}
.brand-text{display:flex;flex-direction:column;line-height:1.3;min-width:0}
.brand-text strong{font-size:14px;font-weight:700;white-space:nowrap}
.brand-text span{font-size:11.5px;color:var(--text-muted)}

.nav{flex:1;padding:14px 12px;overflow-y:auto}
.nav-section{font-size:11px;font-weight:700;color:var(--text-subtle);text-transform:uppercase;letter-spacing:.06em;padding:14px 10px 8px}
.nav-section:first-child{padding-top:4px}
.nav-item{
  display:flex;align-items:center;gap:11px;padding:9px 10px;border-radius:var(--radius-md);
  color:var(--text-muted);font-size:13.5px;font-weight:500;margin-bottom:2px;
  transition:background .15s ease,color .15s ease;
}
.nav-item svg{opacity:.85}
.nav-item:hover{background:var(--surface-3);color:var(--text)}
.nav-item.active{background:var(--accent-soft);color:var(--accent);font-weight:600}
.nav-item.active svg{opacity:1}

.sidebar-foot{padding:14px 18px;border-top:1px solid var(--border)}
.csv-meta{font-size:11.5px;color:var(--text-subtle);line-height:1.5}
.csv-meta strong{color:var(--text-muted);font-weight:600}

/* ===== Topbar ===== */
.topbar{
  position:fixed;top:0;left:var(--sidebar-w);right:0;height:var(--topbar-h);
  background:rgba(13,17,23,.85);backdrop-filter:blur(10px);
  border-bottom:1px solid var(--border);
  display:flex;align-items:center;justify-content:space-between;
  padding:0 24px;z-index:90;
}
.crumbs{font-size:13px;color:var(--text-muted);display:flex;align-items:center;gap:8px}
.crumbs .sep{color:var(--text-subtle)}
.crumbs .current{color:var(--text);font-weight:600}
.topbar-actions{display:flex;align-items:center;gap:12px}
.search-box{
  display:flex;align-items:center;gap:8px;background:var(--surface-3);
  border:1px solid var(--border);border-radius:var(--radius-md);
  padding:0 12px;height:36px;width:280px;transition:border-color .15s ease;
}
.search-box:focus-within{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft)}
.search-box svg{width:15px;height:15px;color:var(--text-subtle)}
.search-box input{background:none;border:none;color:var(--text);font-size:13px;flex:1;outline:none}
.search-box input::placeholder{color:var(--text-subtle)}

/* ===== Buttons ===== */
.btn{
  display:inline-flex;align-items:center;gap:7px;height:36px;padding:0 15px;
  border-radius:var(--radius-md);font-size:13px;font-weight:600;border:1px solid transparent;
  cursor:pointer;transition:transform .1s ease,background .15s ease,border-color .15s ease,opacity .15s ease;
  white-space:nowrap;
}
.btn svg{width:15px;height:15px}
.btn:active{transform:scale(.97)}
.btn:disabled{opacity:.5;cursor:not-allowed;transform:none}
.btn-primary{background:var(--accent);color:#fff}
.btn-primary:hover:not(:disabled){background:var(--accent-hover)}
.btn-ghost{background:var(--surface-3);color:var(--text);border-color:var(--border)}
.btn-ghost:hover:not(:disabled){border-color:var(--border-hover)}
.btn-danger{background:var(--danger-soft);color:var(--danger)}
.btn-danger:hover:not(:disabled){background:#f8514940}
.btn-sm{height:28px;padding:0 11px;font-size:12px;gap:5px}
.btn-sm svg{width:13px;height:13px}
.icon-btn{
  width:30px;height:30px;border-radius:var(--radius-sm);background:transparent;border:none;
  color:var(--text-muted);font-size:20px;line-height:1;cursor:pointer;transition:background .15s ease;
}
.icon-btn:hover{background:var(--surface-3);color:var(--text)}

/* ===== Main layout ===== */
.main{margin-left:var(--sidebar-w);padding-top:calc(var(--topbar-h) + 28px);padding-left:28px;padding-right:28px;padding-bottom:40px;min-height:100vh}
.page-head{display:flex;align-items:flex-end;justify-content:space-between;flex-wrap:wrap;gap:14px;margin-bottom:22px}
.page-head h1{font-size:22px;font-weight:800;letter-spacing:-.01em}
.page-head .muted{color:var(--text-muted);font-size:13px;margin-top:3px}
.filters select{
  height:34px;padding:0 12px;background:var(--surface-3);border:1px solid var(--border);
  border-radius:var(--radius-md);color:var(--text);font-size:13px;
}

/* ===== KPI cards ===== */
.kpi-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:14px;margin-bottom:26px}
.kpi{
  background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-lg);
  padding:18px 20px;transition:border-color .15s ease;position:relative;overflow:hidden;
}
.kpi:hover{border-color:var(--border-hover)}
.kpi .kpi-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px}
.kpi .kpi-icon{
  width:32px;height:32px;border-radius:8px;display:flex;align-items:center;justify-content:center;
}
.kpi .kpi-icon svg{width:16px;height:16px}
.kpi.c-accent .kpi-icon{background:var(--accent-soft);color:var(--accent)}
.kpi.c-success .kpi-icon{background:var(--success-soft);color:var(--success)}
.kpi.c-warning .kpi-icon{background:var(--warning-soft);color:var(--warning)}
.kpi.c-danger .kpi-icon{background:var(--danger-soft);color:var(--danger)}
.kpi .n{font-size:28px;font-weight:800;letter-spacing:-.02em}
.kpi .l{color:var(--text-muted);font-size:12.5px;margin-top:2px;font-weight:500}
.kpi .trend{position:absolute;top:16px;right:18px;font-size:11px;font-weight:700;padding:2px 7px;border-radius:10px}

/* ===== Panels ===== */
.panel{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-lg);margin-bottom:20px;overflow:hidden}
.panel-head{padding:15px 20px;border-bottom:1px solid var(--border);display:flex;align-items:center;justify-content:space-between}
.panel-head h3{font-size:14.5px;font-weight:700}
.panel-body{padding:18px 20px}
.panel-body.no-pad{padding:0}
.link{color:var(--accent);font-size:12.5px;font-weight:600}
.link:hover{color:var(--accent-hover)}

/* ===== Data table ===== */
.dtable{width:100%;border-collapse:collapse;font-size:13.5px}
.dtable thead th{
  text-align:left;font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.05em;
  color:var(--text-subtle);padding:11px 20px;border-bottom:1px solid var(--border);
  background:var(--surface-2);position:sticky;top:0;user-select:none;
}
.dtable thead th.sortable{cursor:pointer}
.dtable thead th.sortable:hover{color:var(--text-muted)}
.dtable thead th .arrow{margin-left:4px;opacity:.4;font-size:10px}
.dtable thead th.sort-active .arrow{opacity:1;color:var(--accent)}
.dtable tbody td{padding:11px 20px;border-bottom:1px solid var(--border);vertical-align:middle}
.dtable tbody tr{transition:background .1s ease;cursor:pointer}
.dtable tbody tr:hover{background:#ffffff08}
.dtable tbody tr:last-child td{border-bottom:none}

.person{display:flex;align-items:center;gap:11px;min-width:0}
.avatar{
  width:34px;height:34px;border-radius:50%;flex-shrink:0;object-fit:cover;
  display:flex;align-items:center;justify-content:center;font-size:12.5px;font-weight:700;color:#fff;
  background:var(--surface-3);
}
.avatar-lg{width:72px;height:72px;font-size:24px;border-radius:16px}
.person .p-name{font-weight:600;font-size:13.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:220px}
.person .p-cpf{font-size:11.5px;color:var(--text-muted);font-family:Consolas,monospace}

.badge{display:inline-flex;align-items:center;gap:5px;font-size:11px;font-weight:600;padding:3px 9px;border-radius:20px;border:1px solid transparent}
.badge-ok{background:var(--success-soft);border-color:#3fb9504d;color:var(--success)}
.badge-warn{background:var(--warning-soft);border-color:#d299224d;color:var(--warning)}
.badge-err{background:var(--danger-soft);border-color:#f851494d;color:var(--danger)}
.badge-muted{background:var(--surface-3);color:var(--text-muted)}
.dot{width:6px;height:6px;border-radius:50%;background:currentColor}

/* ===== Empty state ===== */
.empty-state{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:70px 24px;text-align:center;gap:6px}
.empty-state svg{width:46px;height:46px;color:var(--text-subtle);margin-bottom:10px}
.empty-state .t{font-size:15px;font-weight:700;color:var(--text-muted)}
.empty-state .d{font-size:13px;color:var(--text-subtle);max-width:320px}

/* ===== Detail view ===== */
.detail-head{
  display:flex;align-items:center;justify-content:space-between;gap:16px;flex-wrap:wrap;
  background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-lg);
  padding:22px 24px;margin-bottom:20px;
}
.detail-who{display:flex;align-items:center;gap:16px}
.detail-who h2{font-size:19px;font-weight:800}
.detail-meta{color:var(--text-muted);font-size:12.5px;font-family:Consolas,monospace;margin-top:4px}
.detail-badges{margin-top:8px;display:flex;gap:8px;flex-wrap:wrap}
.back-link{display:inline-flex;align-items:center;gap:6px;color:var(--text-muted);font-size:12.5px;font-weight:600;margin-bottom:14px}
.back-link:hover{color:var(--text)}
.back-link svg{width:14px;height:14px}

.form-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:12px;align-items:end}
.field label{display:block;font-size:11px;color:var(--text-muted);margin-bottom:6px;text-transform:uppercase;letter-spacing:.04em;font-weight:700}
.field input,.field select{
  width:100%;height:38px;padding:0 12px;border-radius:var(--radius-md);border:1px solid var(--border);
  background:var(--surface-3);color:var(--text);font-size:13.5px;transition:border-color .15s ease,box-shadow .15s ease;
}
.field input:focus,.field select:focus{outline:none;border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft)}
.field input[type=file]{padding:8px 12px;height:auto}

/* ===== Day timeline ===== */
.day-group{border-bottom:1px solid var(--border)}
.day-group:last-child{border-bottom:none}
.day-head{
  padding:13px 20px;display:flex;align-items:center;justify-content:space-between;cursor:pointer;
  user-select:none;background:var(--surface-2);transition:background .15s ease;
}
.day-head:hover{background:var(--surface-3)}
.day-head .dh-left{display:flex;align-items:center;gap:10px}
.day-head .dh-date{font-weight:700;font-size:13.5px}
.day-head .dh-week{color:var(--text-muted);font-size:12px}
.day-head .chev{transition:transform .2s ease;color:var(--text-subtle)}
.day-head.collapsed .chev{transform:rotate(-90deg)}
.day-body{padding:4px 0}
.day-body.collapsed{display:none}
.punch{display:flex;align-items:center;gap:14px;padding:10px 20px 10px 32px;border-top:1px solid var(--border)}
.punch:first-child{border-top:none}
.punch .p-time{font-family:Consolas,monospace;font-size:16px;font-weight:700;width:64px;flex-shrink:0}
.punch .p-flex{flex:1;color:var(--text-muted);font-size:12.5px}
.punch .p-nsr{color:var(--text-subtle);font-size:11px;font-family:Consolas,monospace}

/* ===== Modal ===== */
.modal-overlay{
  position:fixed;inset:0;background:rgba(1,4,9,.75);backdrop-filter:blur(4px);
  display:none;align-items:center;justify-content:center;z-index:1000;
}
.modal-overlay.show{display:flex}
.modal{
  background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-lg);
  width:480px;max-width:92vw;box-shadow:0 24px 60px rgba(0,0,0,.5);
  animation:modalIn .16s ease-out;
}
@keyframes modalIn{from{opacity:0;transform:scale(.96) translateY(4px)}to{opacity:1;transform:scale(1) translateY(0)}}
.modal-head{padding:16px 20px;border-bottom:1px solid var(--border);display:flex;align-items:center;justify-content:space-between}
.modal-head h3{font-size:15px;font-weight:700}
.modal-body{padding:20px}
.modal-foot{padding:14px 20px;border-top:1px solid var(--border);display:flex;justify-content:flex-end;gap:10px}

.notice{padding:12px 14px;border-radius:var(--radius-md);font-size:12.5px;margin-bottom:16px;border:1px solid;line-height:1.6}
.notice.warn{background:var(--warning-soft);border-color:#d299224d;color:var(--warning)}
.notice.err{background:var(--danger-soft);border-color:#f851494d;color:var(--danger)}
.notice code{background:rgba(0,0,0,.25);color:inherit}

/* ===== Toast ===== */
.toast{
  position:fixed;bottom:24px;right:24px;padding:13px 18px;border-radius:var(--radius-md);
  font-weight:600;font-size:13px;z-index:2000;box-shadow:0 10px 30px rgba(0,0,0,.5);
  transform:translateY(20px);opacity:0;pointer-events:none;transition:all .2s ease-out;
  display:flex;align-items:center;gap:8px;
}
.toast.show{transform:translateY(0);opacity:1}
.toast.ok{background:var(--success);color:#04260c}
.toast.err{background:var(--danger);color:#2b0605}

/* ===== Loading / skeleton ===== */
.spin{
  display:inline-block;width:14px;height:14px;border:2px solid rgba(255,255,255,.35);
  border-top-color:#fff;border-radius:50%;animation:sp .7s linear infinite;
}
.spin-dark{border-color:var(--border);border-top-color:var(--accent)}
@keyframes sp{to{transform:rotate(360deg)}}
.skeleton-row td{padding:14px 20px}
.skel{height:14px;border-radius:4px;background:linear-gradient(90deg,var(--surface-3) 25%,var(--surface-2) 50%,var(--surface-3) 75%);background-size:200% 100%;animation:shimmer 1.4s infinite}
@keyframes shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}

/* ===== Responsive ===== */
@media(max-width:960px){
  :root{--sidebar-w:0px}
  .sidebar{display:none}
  .topbar{left:0}
  .search-box{width:180px}
}
