/* ATAD Project Profit Tracker -- "ATAD Apps" design system. Dark is the default;
   light is the person's choice (stored as atad-theme, shared with the other apps
   on the same browser address). Cost-head colours are fixed in both themes. */
:root, :root[data-theme="dark"] {
  --bg: #0E131D; --panel: #151C29; --panel-2: #1B2433; --line: #263045;
  --text: #E9ECF2; --muted: #9AA4B7; --faint: #838DA1;
  --accent: #35B9A9; --accent-hover: #5FD3C4; --accent-ink: #062320; --accent-soft: #12302E;
  --red: #F2877A; --red-soft: #3A1D1C; --amber: #EBB55A; --amber-soft: #382A12;
  --green: #6CCB94; --green-soft: #15301F;
  --shadow: 0 12px 32px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #F5F4EF; --panel: #FFFFFF; --panel-2: #F9F8F4; --line: #E2DFD6;
  --text: #171A21; --muted: #565E6D; --faint: #666D7C;
  --accent: #0F7469; --accent-hover: #0B5A51; --accent-ink: #FFFFFF; --accent-soft: #DDF1EE;
  --red: #A8322A; --red-soft: #FBE6E3; --amber: #8A5800; --amber-soft: #FBEFD8;
  --green: #1D6F43; --green-soft: #E0F2E7;
  --shadow: 0 12px 32px rgba(23, 26, 33, .12);
  color-scheme: light;
}
:root {
  --c-mat: #5B9BF0; --c-sub: #A08CF0; --c-lab: #35B9A9; --c-off: #8C96A8; --c-pc: #E0875A; --c-tr: #D77FB3;
  --sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --pad: 40px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 400 14px/21px var(--sans); -webkit-font-smoothing: antialiased; min-width: 320px; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ header */
.hdr { position: sticky; top: 0; z-index: 10; height: 72px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 28px; padding: 0 var(--pad); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: .04em; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand:hover { color: var(--text); }
.brand .ring { color: var(--accent); flex-shrink: 0; }
.brand .app { color: var(--muted); font-weight: 600; font-size: 14px; letter-spacing: 0; padding-left: 12px; border-left: 1px solid var(--line); }
.nav { display: flex; gap: 4px; }
.nav a { padding: 9px 14px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 13px; line-height: 18px; font-weight: 600; white-space: nowrap; }
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.hdr .grow { flex-grow: 1; }
.hdr-tools { display: flex; align-items: center; gap: 12px; }
.hdr-tools .cap { white-space: nowrap; }

/* ------------------------------------------------------------ type */
.h1 { font-size: 28px; line-height: 34px; font-weight: 700; margin: 0; }
.h2 { font-size: 17px; line-height: 24px; font-weight: 700; margin: 0; }
.lbl { font-size: 13px; line-height: 18px; font-weight: 600; color: var(--muted); }
.big { font-size: 30px; line-height: 36px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cap { font-size: 12px; line-height: 16px; color: var(--faint); }
.sub { color: var(--muted); margin-top: 4px; }
.mono { font-family: var(--mono); font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ controls */
.btn { height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--text);
  font: 600 13px var(--sans); display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel-2); color: var(--text); }
.btn.p { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.p:hover { filter: brightness(1.08); }
.btn.icon { width: 40px; padding: 0; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn.icon svg { width: 18px; height: 18px; }
.sel { height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: 400 14px var(--sans); }
.sel::placeholder { color: var(--faint); }
.sel[disabled] { opacity: .6; }
.field { display: flex; flex-direction: column; gap: 6px; }

/* ------------------------------------------------------------ layout */
.main { padding: 32px var(--pad) 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1600px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head .grow { flex: 1 1 320px; }
.filters { display: flex; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.tile { display: flex; flex-direction: column; gap: 8px; }
.tile .big { color: var(--faint); }
.two { display: grid; grid-template-columns: 1.45fr 1fr; gap: 20px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-head { display: flex; align-items: center; gap: 12px; }
.row-head .h2 { flex-grow: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 6px; font-size: 12px; line-height: 16px; font-weight: 600; white-space: nowrap; }
.chip.g { background: var(--green-soft); color: var(--green); }
.chip.am { background: var(--amber-soft); color: var(--amber); }
.chip.r { background: var(--red-soft); color: var(--red); }
.chip.t { background: var(--accent-soft); color: var(--accent); }
.chip.n { background: var(--panel-2); color: var(--muted); }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.track { height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }

/* empty states */
.empty { border: 1px dashed var(--line); border-radius: 10px; padding: 28px 20px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty .h2 { color: var(--text); }
.empty svg { width: 28px; height: 28px; color: var(--faint); }
.heads { display: flex; gap: 2px; height: 28px; border-radius: 8px; overflow: hidden; opacity: .35; }
.heads i { flex: 1; }
.legend { display: grid; grid-template-columns: 1fr auto; row-gap: 12px; column-gap: 12px; align-items: center; }
.legend .head { display: flex; align-items: center; gap: 10px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--faint); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table-card { padding: 8px 8px 4px; }
.table-card .row-head { padding: 12px 12px 6px; }
.table-card td.empty-cell { border-bottom: 0; padding: 16px 12px 20px; }

/* ------------------------------------------------------------ sign in / no access */
.gate { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px 16px; }
.gate-box { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.gate-box .brand { margin-bottom: 4px; }
.gate-box p { margin: 0; color: var(--muted); }
.gate-box .btn { width: 100%; }
.gate-box input.sel { width: 100%; }
.or { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toasts { position: fixed; right: 24px; bottom: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow); max-width: 380px; }
.toast.bad { border-color: var(--red); color: var(--red); }
.toast.ok { border-color: var(--green); }

/* ------------------------------------------------------------ narrower screens */
/* A 1280px laptop: tighten the header so everything stays on one line. */
@media (max-width: 1380px) {
  :root { --pad: 28px; }
  .hdr { gap: 20px; }
  .nav a { padding: 9px 11px; }
}
@media (max-width: 1300px) {
  .hdr-tools .cap { display: none; }
}
@media (max-width: 1180px) {
  .brand .app { display: none; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  :root { --pad: 16px; }
  .hdr { height: auto; flex-wrap: wrap; padding-top: 12px; padding-bottom: 12px; row-gap: 10px; position: static; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .hdr .grow { display: none; }
  .hdr-tools { margin-left: auto; }
  .hdr-tools .refresh-label { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { flex-wrap: wrap; width: 100%; }
  .filters .field { flex: 1 1 160px; }
  .filters .sel { width: 100% !important; }
  .table-card { overflow-x: auto; }
}
