:root {
  --bg: #0e0f11;
  --surface: #17181b;
  --surface-2: #1f2125;
  --line: #2b2e33;
  --text: #f2f2f3;
  --muted: #9a9ea6;
  --red: #e3262f;
  --red-hover: #f03a42;
  --red-soft: rgba(227, 38, 47, 0.14);
  --green: #2fbf71;
  --green-soft: rgba(47, 191, 113, 0.14);
  --amber: #f0a73a;
  --amber-soft: rgba(240, 167, 58, 0.14);
  --radius: 12px;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 22px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }
.muted { color: var(--muted); }
.error { color: #ff6b70; font-size: 14px; margin: 4px 0 0; }
.info { color: var(--green); font-size: 14px; margin: 4px 0 0; }

.screen { min-height: 100vh; }
.center { display: grid; place-items: center; padding: 16px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: #3a3e45; background: #26292e; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-hover); border-color: var(--red-hover); }
.btn.danger { background: transparent; border-color: rgba(227,38,47,.5); color: #ff6b70; }
.btn.danger:hover { background: var(--red-soft); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 7px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; padding: 8px 0; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--text); }

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.field.inline { margin: 0; }
input, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--red); outline-offset: -1px; border-color: transparent; }

/* Auth */
.auth { display: grid; grid-template-columns: 1.3fr 1fr; }
.auth-hero { position: relative; overflow: hidden; background: #000; }
.auth-hero img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .85; }
.auth-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0) 40%, rgba(0,0,0,.85) 100%); }
.auth-hero-text { position: absolute; left: 40px; right: 40px; bottom: 40px; z-index: 1; }
.auth-hero-text h1 { font-size: 44px; font-weight: 700; letter-spacing: -.02em; }
.auth-hero-text p { margin: 6px 0 0; color: #d6d7da; font-size: 17px; }
.eyebrow { display: inline-block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; color: var(--red); margin-bottom: 8px; }
.auth-panel { display: flex; flex-direction: column; justify-content: center; padding: 48px; max-width: 460px; width: 100%; margin: 0 auto; }
.seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 24px; }
.seg-btn { flex: 1; background: none; border: 0; color: var(--muted); font: inherit; font-weight: 600; padding: 9px; border-radius: 9px; cursor: pointer; }
.seg-btn.active { background: var(--surface-2); color: var(--text); }

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .auth-hero { height: 260px; }
  .auth-hero-text { left: 16px; right: 16px; bottom: 18px; }
  .auth-hero-text h1 { font-size: 32px; }
  .auth-panel { padding: 24px 16px 40px; }
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.card.narrow { max-width: 420px; }
.card p { margin: 10px 0 20px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; background: rgba(14,15,17,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand-mark { width: 22px; height: 4px; background: var(--red); border-radius: 2px; box-shadow: 0 0 12px rgba(227,38,47,.6); }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab { background: none; border: 0; color: var(--muted); font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--surface-2); }
.who { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; white-space: nowrap; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .tabs { order: 3; flex-basis: 100%; overflow-x: auto; }
  .who { margin-left: auto; }
  #who-name { display: none; }
}

main { max-width: 1100px; margin: 0 auto; padding: 28px 24px 60px; }
@media (max-width: 720px) { main { padding: 20px 16px 48px; } }

.panel-head { margin-bottom: 18px; }
.panel-head p { margin: 6px 0 0; font-size: 14px; }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.row.gap { gap: 8px; }
.row.space { justify-content: space-between; gap: 12px; }
.panel-head.row { justify-content: space-between; gap: 12px; }

/* Clock */
.clock-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 36px 24px;
  text-align: center; max-width: 520px; margin: 0 auto; position: relative; overflow: hidden;
}
.clock-card::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--line); }
.clock-card.on::before { background: var(--green); box-shadow: 0 0 16px var(--green); }
.clock-status { display: inline-block; font-size: 13px; font-weight: 600; padding: 4px 12px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.clock-card.on .clock-status { background: var(--green-soft); color: var(--green); }
.clock-timer { font-family: var(--mono); font-size: 56px; letter-spacing: .02em; margin: 18px 0 4px; font-variant-numeric: tabular-nums; }
.clock-since { font-size: 14px; margin-bottom: 24px; }
.btn.huge { width: 100%; max-width: 320px; padding: 18px; font-size: 18px; border-radius: 14px; background: var(--red); border-color: var(--red); color: #fff; }
.btn.huge:hover { background: var(--red-hover); }
.btn.huge.out { background: var(--surface-2); border-color: var(--line); color: var(--text); }
.btn.huge.out:hover { background: #2a2d32; }
@media (max-width: 480px) { .clock-timer { font-size: 44px; } }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 520px; margin: 16px auto 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 480px) { .stats { grid-template-columns: 1fr 1fr; } .stat:last-child { grid-column: span 2; } }
[data-panel="clock"] h3, [data-panel="clock"] .table-wrap { max-width: 520px; margin-left: auto; margin-right: auto; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { border-top: 1px solid var(--line); font-weight: 700; padding: 10px 14px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table td.nowrap { white-space: nowrap; }
.table input, .table select { padding: 7px 10px; font-size: 14px; }
.rate-input { display: flex; align-items: center; gap: 6px; max-width: 150px; }
.rate-input input { width: 100px; }
.person strong { display: block; font-weight: 600; }
.person span { color: var(--muted); font-size: 13px; }
tr.pending td { background: var(--amber-soft); }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.on { background: var(--green-soft); color: var(--green); }
.badge.wait { background: var(--amber-soft); color: var(--amber); }
.badge.open { background: var(--red-soft); color: #ff6b70; }
.edited { font-size: 12px; color: var(--muted); }
.saved-flash { color: var(--green); font-size: 12px; }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; cursor: pointer; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(18px); }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.filters .field { width: 170px; }

/* Dialog */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 24px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 18px; margin: 0 0 18px; }
.person-line { margin: -4px 0 14px; font-size: 14px; }

/* Pay periods */
.period-note { max-width: 520px; margin: 10px auto 0; font-size: 13px; text-align: center; }
.period-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.period-title { min-width: 200px; text-align: center; padding: 0 8px; }
.period-title .eyebrow { margin-bottom: 2px; }
.period-title h2 { font-size: 26px; letter-spacing: -.01em; }
.btn.icon { font-size: 22px; line-height: 1; padding: 4px 14px 8px; }
#ts-current { margin-left: auto; }

.pay-stats { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 12px; }
.pay-stats .stat.big { background: linear-gradient(135deg, rgba(227,38,47,.18), var(--surface) 70%); border-color: rgba(227,38,47,.35); }
.pay-stats .stat.big .stat-value { font-size: 30px; }
.stat.warn { border-color: rgba(227,38,47,.5); }
.stat.warn .stat-value { color: #ff6b70; }
.warning { margin: 12px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--red-soft); color: #ff8a8e; font-size: 14px; }
@media (max-width: 720px) {
  .pay-stats { grid-template-columns: 1fr 1fr; }
  .pay-stats .stat.big { grid-column: span 2; }
  .period-title { flex: 1; min-width: 0; }
  .period-title h2 { font-size: 21px; }
  #ts-current { margin-left: 0; }
}

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 28px 0 10px; }
.section-head h3 { margin: 0; }
.table tr.zero td { color: var(--muted); }
.table td.strong { font-weight: 700; }
.custom-range { margin-bottom: 12px; }
.custom-range summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 4px 0 10px; }
.custom-range summary:hover { color: var(--text); }
.filters .error { flex-basis: 100%; margin: 0; }
@media (max-width: 560px) {
  .payroll-table th:nth-child(2), .payroll-table td:nth-child(2),
  .payroll-table th:nth-child(4), .payroll-table td:nth-child(4) { display: none; }
  .payroll-table td, .payroll-table th { padding: 10px; }
}

/* Team tab: unsaved edits + admin-only fields */
.savebar {
  position: sticky; top: 64px; z-index: 4; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px; padding: 10px 14px; border-radius: 12px; background: var(--amber-soft); border: 1px solid rgba(240,167,58,.45); color: var(--amber); font-weight: 600; font-size: 14px;
}
.savebar .error { flex-basis: 100%; order: 3; }
.saved-note { margin: 0 0 12px; color: var(--green); font-weight: 600; font-size: 14px; }
.table tr.dirty td { background: rgba(240,167,58,.07); }
.table tr.dirty td:first-child { box-shadow: inset 3px 0 0 var(--amber); }
.text-input { min-width: 160px; }
.notes-input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; font-size: 14px; width: 100%; min-width: 220px; resize: vertical; min-height: 36px; line-height: 1.4; }
.notes-input:focus { outline: 2px solid var(--red); outline-offset: -1px; border-color: transparent; }
@media (max-width: 720px) { .savebar { top: 96px; } }
@media (max-width: 560px) {
  .payroll-table th:nth-child(2), .payroll-table td:nth-child(2) { display: none; }
  .payroll-table th:nth-child(3), .payroll-table td:nth-child(3),
  .payroll-table th:nth-child(5), .payroll-table td:nth-child(5) { display: none; }
  .payroll-table th:nth-child(4), .payroll-table td:nth-child(4) { display: table-cell; }
}
.table select[data-field="role"] { min-width: 100px; }
.table .rate-input input { min-width: 90px; }
