:root {
  color-scheme: light;
  --navy: #0b1f3a;
  --navy-soft: #173d67;
  --gold: #c69b3c;
  --gold-bright: #e0b95e;
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f7f9fb;
  --text: #152334;
  --muted: #667486;
  --line: #d6dee8;
  --good: #14734b;
  --good-bg: #e7f6ef;
  --warn: #8b5700;
  --warn-bg: #fff3d5;
  --bad: #a12d35;
  --bad-bg: #fdebed;
  --info: #2369a5;
  --shadow: 0 10px 30px rgba(18, 37, 58, .10);
  --radius: 14px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07121f;
  --panel: #0e2033;
  --panel-soft: #132a42;
  --text: #edf3f8;
  --muted: #9bacc0;
  --line: #29425c;
  --good: #68d5a4;
  --good-bg: #123c31;
  --warn: #ffd079;
  --warn-bg: #493718;
  --bad: #ff9ba2;
  --bad-bg: #492227;
  --info: #7dc1ff;
  --shadow: 0 12px 32px rgba(0, 0, 0, .28);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #07121f;
    --panel: #0e2033;
    --panel-soft: #132a42;
    --text: #edf3f8;
    --muted: #9bacc0;
    --line: #29425c;
    --good: #68d5a4;
    --good-bg: #123c31;
    --warn: #ffd079;
    --warn-bg: #493718;
    --bad: #ff9ba2;
    --bad-bg: #492227;
    --info: #7dc1ff;
    --shadow: 0 12px 32px rgba(0, 0, 0, .28);
  }
  :root[data-theme="system"] .authLogo .logoLight { display: none; }
  :root[data-theme="system"] .authLogo .logoDark { display: block; }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: var(--info); }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.5rem, 3vw, 2.2rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
.hidden { display: none !important; }
.muted, .hint { color: var(--muted); }
.hint { font-size: .87rem; }
.centered { text-align: center; }
.dangerText { color: var(--bad); }
.goodText { color: var(--good); }

.connectionBanner { position: fixed; z-index: 1000; inset: 0 0 auto; padding: 9px 16px; text-align: center; color: #fff; background: var(--bad); font-weight: 700; }
.connectionBanner:not(.hidden) ~ .appShell .topbar { top: 40px; }

.authPage { min-height: 100vh; display: grid; place-items: center; padding: 28px 16px; background: radial-gradient(circle at 20% 10%, rgba(198,155,60,.2), transparent 30%), linear-gradient(145deg, var(--navy), #071321 65%); }
.authCard { width: min(680px, 100%); padding: clamp(24px, 5vw, 44px); border: 1px solid rgba(255,255,255,.16); border-radius: 22px; color: var(--text); background: var(--panel); box-shadow: 0 24px 70px rgba(0,0,0,.35); }
.authCard.compact { width: min(460px, 100%); }
.authBrand { display: flex; align-items: center; gap: 16px; margin-bottom: 28px; }
.authBrand h1, .authBrand p { margin: 0; }
.authLogo { position: relative; display: block; width: clamp(155px, 32vw, 235px); aspect-ratio: 3.24 / 1; flex: 0 0 auto; }
.authLogo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.authLogo .logoDark { display: none; }
[data-theme="dark"] .authLogo .logoLight { display: none; }
[data-theme="dark"] .authLogo .logoDark { display: block; }
.mark { display: grid; place-items: center; width: 70px; aspect-ratio: 1; flex: 0 0 auto; border-radius: 18px; color: #fff; background: linear-gradient(145deg, var(--gold-bright), #9b7220); font-weight: 900; font-size: 1.65rem; box-shadow: inset 0 0 0 2px rgba(255,255,255,.2); }
.mark.small { width: 42px; border-radius: 10px; font-size: 1rem; }

.stack { display: grid; gap: 15px; }
.formGrid { display: grid; gap: 14px; }
.formGrid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.formGrid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: grid; gap: 6px; color: var(--muted); font-weight: 650; font-size: .88rem; }
input, select, textarea { width: 100%; min-height: 43px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--panel); outline: none; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(198,155,60,.18); }
input[type="checkbox"] { width: 18px; min-height: 18px; }

button { min-height: 44px; padding: 9px 14px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--panel); font-weight: 750; }
button:hover { border-color: var(--gold); }
button.primary { border-color: var(--gold); color: #102033; background: linear-gradient(135deg, var(--gold-bright), var(--gold)); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
button.quiet { min-height: 34px; padding: 6px 10px; color: var(--muted); background: transparent; }
button.small { min-height: 34px; padding: 6px 9px; font-size: .83rem; }
.iconButton { min-width: 44px; width: 44px; padding: 0; display: grid; place-items: center; border-radius: 10px; }

.appShell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); grid-template-rows: 72px minmax(0, 1fr); }
.topbar { position: sticky; top: 0; z-index: 30; grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 18px; min-width: 0; padding: 10px 18px; color: #fff; background: var(--navy); box-shadow: 0 4px 18px rgba(0,0,0,.18); }
.brandInline { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbarLogo { width: 118px; height: 48px; object-fit: contain; }
.brandInline div { display: grid; min-width: 0; }
.brandInline strong, .brandInline span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brandInline span { color: #c7d3df; font-size: .78rem; }
.topActions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; min-width: 0; }
.topActions button { color: #fff; border-color: rgba(255,255,255,.22); background: rgba(255,255,255,.08); }
.weekPicker { display: flex; align-items: center; gap: 7px; color: #c7d3df; }
.weekPicker input { width: 145px; min-height: 38px; color: #fff; border-color: rgba(255,255,255,.22); background: rgba(255,255,255,.08); color-scheme: dark; }
.accountButton { display: grid; justify-items: end; min-height: 44px; padding: 5px 10px; }
.accountButton small { color: #c7d3df; font-weight: 500; }
.menuButton { display: none; }

.sidebar { position: sticky; top: 72px; height: calc(100vh - 72px); z-index: 25; display: flex; flex-direction: column; padding: 14px 10px; color: #e9f0f6; background: #0d2743; overflow-y: auto; }
.sidebar nav { display: grid; gap: 14px; }
.navGroup { display: grid; gap: 4px; }
.navGroupLabel { padding: 4px 10px 2px; color: #8fa6ba; font-size: .68rem; font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }
.sidebar nav button { display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 9px; width: 100%; min-height: 44px; padding: 8px 10px; border: 0; text-align: left; color: #d8e4ee; background: transparent; }
.sidebar nav button:hover { background: rgba(255,255,255,.08); }
.sidebar nav button.active { color: #fff; background: rgba(198,155,60,.22); box-shadow: inset 3px 0 var(--gold); }
.navIcon { font-size: 1.1rem; text-align: center; }
.sidebarFoot { margin-top: auto; padding: 14px 7px 4px; border-top: 1px solid rgba(255,255,255,.13); color: #9fb0c1; font-size: .78rem; }
.sidebarFoot button { min-height: 44px; color: #c7d3df; }

.content { min-width: 0; padding: clamp(16px, 3vw, 32px); overflow-x: hidden; }
.pageHeader { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.pageHeader h1 { margin-bottom: 4px; }
.pageHeader p { margin-bottom: 0; color: var(--muted); }
.pageActions, .inlineActions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.metricGrid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 13px; margin-bottom: 18px; }
.metric { padding: 17px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.metric strong { display: block; margin-top: 4px; font-size: 1.65rem; line-height: 1.05; }
.metric span { color: var(--muted); font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.metric.good { border-left: 4px solid var(--good); }
.metric.warn { border-left: 4px solid var(--warn); }
.metric.bad { border-left: 4px solid var(--bad); }

.layoutGrid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 15px; align-items: start; }
.span4 { grid-column: span 4; }.span5 { grid-column: span 5; }.span6 { grid-column: span 6; }.span7 { grid-column: span 7; }.span8 { grid-column: span 8; }.span12 { grid-column: 1 / -1; }
.card { min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.cardHead { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.cardHead h2, .cardHead h3, .cardHead p { margin-bottom: 0; }
.cardHead p { color: var(--muted); }
.subtlePanel { padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); }
.empty { padding: 30px 18px; text-align: center; color: var(--muted); }

.tableWrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 11px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); background: var(--panel-soft); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
td.number, th.number { text-align: right; }
tbody tr:hover { background: color-mix(in srgb, var(--panel-soft) 70%, transparent); }
.mobileCards { display: none; }

.statusPill, .tag { display: inline-flex; align-items: center; width: fit-content; min-height: 25px; padding: 3px 8px; border-radius: 999px; background: var(--panel-soft); color: var(--muted); font-size: .75rem; font-weight: 800; }
.statusPill.good, .tag.good { color: var(--good); background: var(--good-bg); }
.statusPill.warn, .tag.warn { color: var(--warn); background: var(--warn-bg); }
.statusPill.bad, .tag.bad { color: var(--bad); background: var(--bad-bg); }
.warningList { display: grid; gap: 7px; margin: 12px 0; }
.warning { padding: 9px 11px; border-radius: 8px; color: var(--warn); background: var(--warn-bg); font-size: .85rem; }
.warning.blocker { color: var(--bad); background: var(--bad-bg); }

.personJobBoard { display: grid; gap: 10px; }
.jobGroup { overflow: hidden; border: 1px solid var(--line); border-radius: 11px; }
.jobGroupHead { display: flex; justify-content: space-between; gap: 12px; padding: 11px 13px; background: var(--panel-soft); font-weight: 800; }
.jobPeople { display: flex; flex-wrap: wrap; gap: 7px; padding: 12px; }
.personChip { padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); font-size: .84rem; }

.sheetCard { border-left: 4px solid var(--line); }
.sheetCard[data-status="Submitted"] { border-left-color: var(--warn); }
.sheetCard[data-status="Approved"] { border-left-color: var(--good); }
.sheetCard[data-status="Closed"] { border-left-color: var(--navy-soft); }
.sheetTotals { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); }
.sheetTotals strong { color: var(--text); }
.codeHours { display: flex; flex-wrap: wrap; gap: 6px; }
.permissionGrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 12px; }
.checkRow { display: flex; align-items: center; gap: 8px; min-height: 44px; color: var(--text); font-size: .83rem; }

.modal { width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 1px solid var(--line); border-radius: 16px; color: var(--text); background: var(--panel); box-shadow: 0 30px 90px rgba(0,0,0,.4); }
.modal::backdrop { background: rgba(3,12,22,.68); backdrop-filter: blur(3px); }
.modalFrame { margin: 0; }
.modalHead { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.modalHead h2 { margin: 0; }
.modalBody { padding: 18px; overflow-y: auto; }
.modalActions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 9px; padding: 13px 18px; border-top: 1px solid var(--line); background: var(--panel); }

.toastRegion { position: fixed; z-index: 2000; right: 16px; bottom: 16px; display: grid; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast { padding: 12px 14px; border: 1px solid var(--line); border-left: 4px solid var(--good); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); }
.toast.error { border-left-color: var(--bad); }
.loading { min-height: 250px; display: grid; place-items: center; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1050px) {
  .metricGrid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .span4, .span5, .span6, .span7, .span8 { grid-column: span 6; }
}

@media (max-width: 800px) {
  button, button.small, button.quiet, button.iconButton, input, select { min-height: 44px; }
  .appShell { display: block; padding-top: 64px; }
  .topbar { position: fixed; height: 64px; inset: 0 0 auto; padding: 8px 10px; }
  .menuButton { display: grid; }
  .brandInline strong { max-width: 180px; }
  .topbarLogo, .brandInline span { display: none; }
  .weekPicker span, .statusPill { display: none; }
  .weekPicker input { width: 132px; }
  .accountButton { display: none; }
  .sidebar { position: fixed; top: 0; left: 0; z-index: 80; width: min(300px, 86vw); height: 100vh; padding-top: 72px; transform: translateX(-105%); transition: transform .2s ease; box-shadow: 15px 0 40px rgba(0,0,0,.3); }
  .sidebar.open { transform: translateX(0); }
  .navScrim { position: fixed; z-index: 70; inset: 0; display: block !important; background: rgba(0,0,0,.45); }
  .navScrim.hidden { display: none !important; }
  .content { padding: 18px 12px 80px; }
  .formGrid.two, .formGrid.three { grid-template-columns: 1fr; }
  .span4, .span5, .span6, .span7, .span8 { grid-column: 1 / -1; }
}

@media (max-width: 600px) {
  .metricGrid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric { padding: 13px; }
  .metric strong { font-size: 1.35rem; }
  .pageHeader { display: block; }
  .pageActions { margin-top: 12px; }
  .desktopTable { display: none; }
  .mobileCards { display: grid; gap: 9px; padding: 10px; }
  .mobileRow { display: grid; gap: 7px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); }
  .mobileRowHead { display: flex; justify-content: space-between; gap: 10px; }
  .permissionGrid { grid-template-columns: 1fr; }
  .authCard { padding: 23px 18px; }
  .authBrand { align-items: flex-start; flex-direction: column; }
  .authLogo { width: 190px; }
}

@media (max-width: 420px) {
  .brandInline { display: none; }
}

@media print {
  .topbar, .sidebar, .pageActions, button, .connectionBanner { display: none !important; }
  .appShell { display: block; }
  .content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
