/* ===========================================================================
   Tally Sync — base, layout and components
   =========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 400 var(--fs-body)/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
h1,h2,h3,h4 { margin: 0; color: var(--ink); font-weight: 600; line-height: 1.25; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Numbers must always align and never be mistaken for prose. */
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { text-align: right; font-weight: 500; white-space: nowrap; }
.neg { color: var(--red); }
.pos { color: var(--green); }
.dim { color: var(--muted); }
.faint { color: var(--faint); }
.grow { flex: 1; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ===================== shell ===================== */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.side {
  background: var(--brand-deep); color: #AFC6E4;
  display: flex; flex-direction: column; padding-bottom: var(--s5);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-brand {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s5) var(--s5) var(--s4);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.side-brand .mark {
  width: 38px; height: 38px; border-radius: 9px; background: #fff; color: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: 19px;
  letter-spacing: -.03em; flex: 0 0 auto;
}
.side-brand b { display: block; color: #fff; font-size: 15.5px; letter-spacing: -.01em; }
.side-brand span { font-size: 11px; color: #7E9AC4; }

.side-group {
  padding: 17px var(--s5) 7px; font: 600 10px/1 var(--mono);
  letter-spacing: .16em; text-transform: uppercase; color: #5C7BA8;
}
.side a.nav {
  display: flex; align-items: center; gap: 11px; padding: 8px var(--s5);
  color: #AFC6E4; font-size: 14px; border-left: 3px solid transparent;
  transition: background var(--t-fast), color var(--t-fast);
}
.side a.nav:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.side a.nav.on { background: rgba(0,81,225,.22); color: #fff; border-left-color: var(--live); font-weight: 500; }
.side a.nav .ico { width: 17px; text-align: center; font-size: 13px; opacity: .9; }
.side a.nav .count {
  margin-left: auto; background: var(--red); color: #fff; font-size: 10.5px;
  font-weight: 600; padding: 1px 6px; border-radius: 10px;
}
.side-base {
  margin-top: auto; padding: var(--s4) var(--s5) 0;
  border-top: 1px solid rgba(255,255,255,.09); font-size: 12px; color: #7E9AC4;
}
.side-base b { display: block; color: #fff; font-size: 13px; font-weight: 500; }

main { min-width: 0; display: flex; flex-direction: column; }

/* ===================== top bar ===================== */
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px var(--s6); display: flex; align-items: center; gap: var(--s3);
  position: sticky; top: 0; z-index: 20; min-height: var(--topbar-h); flex-wrap: wrap;
}
.topbar .search-btn {
  display: flex; align-items: center; gap: var(--s2); padding: 6px 12px;
  border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--bg);
  color: var(--muted); font-size: 13px; min-width: 180px;
}
.topbar .search-btn kbd {
  margin-left: auto; font: 500 11px var(--mono); background: #fff;
  border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; color: var(--faint);
}
.icon-btn {
  width: 34px; height: 34px; border-radius: var(--r-ctl); border: 1px solid transparent;
  background: transparent; color: var(--body); display: grid; place-items: center;
  position: relative; font-size: 15px;
}
.icon-btn:hover { background: var(--brand-wash); color: var(--brand); }
.icon-btn .badge {
  position: absolute; top: 2px; right: 2px; min-width: 15px; height: 15px;
  background: var(--red); color: #fff; border-radius: 8px; font-size: 9.5px;
  font-weight: 700; display: grid; place-items: center; padding: 0 3px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand-wash);
  color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 13px;
  border: 1px solid var(--brand-line);
}

.page { padding: var(--s6); max-width: var(--content-max); width: 100%; }
.page-head { margin-bottom: var(--s6); }
.page-head h1 { font-size: var(--fs-page); letter-spacing: -.025em; margin-bottom: 4px; }
.page-head .as-of { color: var(--muted); font-size: 14px; }
.page-head-row { display: flex; align-items: flex-start; gap: var(--s3); flex-wrap: wrap; }

/* ===================== buttons ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  background: var(--brand); color: #fff; border: 1px solid var(--brand);
  padding: 9px 17px; border-radius: var(--r-ctl); font-weight: 500; font-size: 14px;
  white-space: nowrap; transition: background var(--t-fast), border-color var(--t-fast);
}
.btn:hover:not(:disabled) { background: var(--brand-press); border-color: var(--brand-press); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.sec { background: #fff; color: var(--brand); border-color: var(--brand-line); }
.btn.sec:hover:not(:disabled) { background: var(--brand-wash); }
.btn.ghost { background: transparent; color: var(--body); border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { background: var(--bg); }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red-line); }
.btn.danger:hover:not(:disabled) { background: var(--red-bg); }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn.lg { padding: 12px 22px; font-size: 15px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }

/* ===================== form ===================== */
.field { margin-bottom: var(--s4); }
.field > label { display: block; font-size: var(--fs-label); font-weight: 500; color: var(--body); margin-bottom: 6px; }
.input, .select, textarea.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); background: #fff;
  font: 400 var(--fs-body)/1.4 var(--sans); color: var(--ink); border-radius: var(--r-ctl);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input:hover, .select:hover { border-color: #CBD5E1; }
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--brand); box-shadow: var(--ring);
}
.input:disabled, .select:disabled { background: var(--bg); color: var(--faint); cursor: not-allowed; }
.input.money { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; font-weight: 500; font-size: 16px; }
.input.err { border-color: var(--red); }
.hint { font-size: var(--fs-hint); color: var(--faint); margin-top: 5px; }
.hint.err { color: var(--red); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--s4); }
.check { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-body); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

/* searchable combo */
.combo { position: relative; }
.combo-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff;
  border: 1px solid var(--line); border-radius: var(--r-ctl); box-shadow: var(--shadow-lift);
  max-height: 260px; overflow-y: auto; z-index: 40;
}
.combo-opt { padding: 9px 12px; font-size: var(--fs-body); display: flex; align-items: center; gap: var(--s2); cursor: pointer; }
.combo-opt:hover, .combo-opt.hi { background: var(--brand-wash); }
.combo-opt .sub { color: var(--faint); font-size: 12px; margin-left: auto; }
.combo-sep { padding: 6px 12px; font: 600 10px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--faint); background: var(--bg); }
.combo-none { padding: 12px; font-size: 13px; color: var(--muted); }

/* ===================== card ===================== */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card);
  box-shadow: var(--shadow); margin-bottom: var(--s5); overflow: hidden;
}
.card > h2, .card-head {
  font-size: var(--fs-card); font-weight: 600; margin: 0; padding: 14px 19px;
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: var(--s3);
}
.card-body { padding: 19px; }
.card-body.flush { padding: 0; }
.card-foot { padding: 12px 19px; border-top: 1px solid var(--line); background: #FBFDFF; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: var(--s3); }

/* ===================== kpi ===================== */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--s4); margin-bottom: var(--s5); }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card);
  padding: 16px 18px; box-shadow: var(--shadow); text-align: left; width: 100%;
  transition: border-color var(--t-fast), transform var(--t-fast);
}
button.kpi { cursor: pointer; }
button.kpi:hover { border-color: var(--brand-line); transform: translateY(-1px); }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .v { font-size: var(--fs-kpi); font-weight: 600; letter-spacing: -.03em; margin-top: 9px;
  font-variant-numeric: tabular-nums; color: var(--ink); line-height: 1.1; }
.kpi .v.g { color: var(--green); } .kpi .v.a { color: var(--amber); } .kpi .v.r { color: var(--red); }
.kpi .n { font-size: 12px; color: var(--faint); margin-top: 5px; }

/* ===================== table ===================== */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-table); }
.tbl th {
  text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; padding: 11px 19px;
  border-bottom: 1px solid var(--line); background: #FBFDFF; white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.tbl td { padding: 11px 19px; border-bottom: 1px solid var(--line-2); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr:hover { background: var(--hover); }
.tbl tr.row-bad { background: var(--red-bg); }
.tbl tr.row-warn { background: var(--amber-bg); }
.tbl tfoot td { font-weight: 600; background: #FBFDFF; border-top: 1px solid var(--line); }
.tbl .msg { font-size: 12.5px; color: #8F2B20; padding: 10px 19px; background: var(--red-bg); }

/* ===================== pill ===================== */
.pill {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 9px;
  border-radius: 999px; border: 1px solid; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
.pill.ok   { color: var(--green); background: var(--green-bg); border-color: var(--green-line); }
.pill.warn { color: var(--amber); background: var(--amber-bg); border-color: var(--amber-line); }
.pill.bad  { color: var(--red);   background: var(--red-bg);   border-color: var(--red-line); }
.pill.info { color: var(--brand); background: var(--brand-wash); border-color: var(--brand-line); }
.pill.dot::before { content: "●"; margin-right: 5px; font-size: 8px; vertical-align: 1px; }
.pill.live::before { animation: pulse 2.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* ===================== notes / banners ===================== */
.note {
  padding: 13px 16px; border-radius: var(--r-ctl); font-size: 13.8px;
  margin-bottom: var(--s5); border: 1px solid; border-left-width: 3px;
}
.note b { display: block; margin-bottom: 3px; }
.note .sub { font-size: 13px; margin-top: 5px; opacity: .92; }
.note.info { background: var(--brand-wash); border-color: var(--brand-line); border-left-color: var(--brand); color: var(--brand-deep); }
.note.ok   { background: var(--green-bg); border-color: var(--green-line); border-left-color: var(--green); color: #0B5C3C; }
.note.warn { background: var(--amber-bg); border-color: var(--amber-line); border-left-color: var(--amber); color: #7D5000; }
.note.err  { background: var(--red-bg);   border-color: var(--red-line);   border-left-color: var(--red);   color: #8F2B20; }

.banner {
  padding: 11px var(--s6); font-size: 13.5px; display: flex; align-items: center; gap: var(--s3);
  border-bottom: 1px solid;
}
.banner.warn { background: var(--amber-bg); border-color: var(--amber-line); color: #7D5000; }
.banner.err  { background: var(--red-bg);   border-color: var(--red-line);   color: #8F2B20; }

/* ===================== filter bar ===================== */
.filters { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; padding: 12px 19px; }
.filters .select, .filters .input { width: auto; min-width: 130px; padding: 7px 10px; font-size: 13px; }
.filters .search { flex: 1; min-width: 160px; }

/* ===================== tabs ===================== */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: var(--s5); overflow-x: auto; }
.tab {
  padding: 10px 14px; font-size: 13.8px; color: var(--muted); background: none;
  border: none; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ===================== modal / drawer ===================== */
.overlay {
  position: fixed; inset: 0; background: rgba(11,26,46,.42); z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center; padding: var(--s5);
  animation: fade var(--t);
}
@keyframes fade { from { opacity: 0 } }
.modal {
  background: #fff; border-radius: var(--r-card); box-shadow: var(--shadow-lift);
  width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column;
  animation: rise var(--t);
}
@keyframes rise { from { transform: translateY(10px); opacity: 0 } }
.modal.wide { max-width: 780px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: var(--s3); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: var(--s3); background: #FBFDFF; }

.drawer-wrap { position: fixed; inset: 0; z-index: var(--z-drawer); display: flex; justify-content: flex-end; }
.drawer-scrim { position: absolute; inset: 0; background: rgba(11,26,46,.32); animation: fade var(--t); }
.drawer {
  position: relative; background: #fff; width: 100%; max-width: 460px; height: 100%;
  box-shadow: var(--shadow-lift); display: flex; flex-direction: column; animation: slide var(--t);
}
@keyframes slide { from { transform: translateX(24px); opacity: .6 } }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: var(--s3); }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }

/* ===================== toast ===================== */
.toasts { position: fixed; right: var(--s5); bottom: var(--s5); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--s2); }
.toast {
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--r-ctl);
  font-size: 13.5px; box-shadow: var(--shadow-lift); display: flex; align-items: center; gap: var(--s3);
  max-width: 400px; animation: rise var(--t);
}
.toast .ref { font-family: var(--mono); font-size: 12px; color: #9FC0E8; }
.toast.ok { background: #0B5C3C; }
.toast button { background: none; border: none; color: #9FC0E8; font-size: 13px; padding: 0; }

/* ===================== empty / skeleton ===================== */
.empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.empty .ico { font-size: 30px; opacity: .3; margin-bottom: var(--s3); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 5px; }
.empty .btn { margin-top: var(--s4); }
.sk { background: linear-gradient(90deg, var(--line-2) 25%, #E8EEF6 37%, var(--line-2) 63%);
  background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-sm); }
@keyframes shimmer { from { background-position: 100% 50% } to { background-position: 0 50% } }
.sk-row { height: 14px; margin: 12px 19px; }

/* ===================== steps ===================== */
.steps { display: flex; gap: var(--s3); margin-bottom: var(--s6); }
.step { flex: 1; text-align: center; font-size: 12.5px; color: var(--muted); }
.step .bar { height: 4px; border-radius: 2px; background: var(--line); margin-bottom: 8px; }
.step.done .bar { background: var(--green); } .step.done { color: var(--green); }
.step.on .bar { background: var(--brand); } .step.on { color: var(--brand); font-weight: 600; }

/* ===================== auth ===================== */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.auth-brand {
  background: linear-gradient(158deg, var(--brand-deep-2), var(--brand-deep) 55%, #04203F);
  color: #fff; padding: 52px 56px; display: flex; flex-direction: column; justify-content: center;
  position: relative; overflow: hidden;
}
.auth-brand::after { content: ""; position: absolute; right: -140px; bottom: -160px; width: 460px; height: 460px; border-radius: 50%; background: rgba(255,255,255,.05); }
.auth-brand .mark { background: #fff; color: var(--brand); width: 46px; height: 46px; border-radius: 11px; display: grid; place-items: center; font-weight: 700; font-size: 22px; }
.auth-brand h2 { color: #fff; font-size: 31px; letter-spacing: -.03em; margin: 28px 0 12px; max-width: 15ch; line-height: 1.15; }
.auth-brand p { font-size: 15px; color: #C4D8F0; margin: 0 0 28px; max-width: 44ch; }
.auth-brand ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 11px; position: relative; z-index: 1; }
.auth-brand li { display: flex; gap: 11px; font-size: 14px; color: #DCE9F9; }
.auth-brand li b { color: #fff; }
.tick { flex: 0 0 auto; width: 19px; height: 19px; border-radius: 50%; background: rgba(255,255,255,.16); display: grid; place-items: center; font-size: 11px; margin-top: 1px; }
.auth-brand .foot { margin-top: 36px; padding-top: 20px; border-top: 1px solid rgba(255,255,255,.14); font-size: 12.5px; color: #A8C4E5; position: relative; z-index: 1; }
.auth-form { display: grid; place-items: center; padding: 40px 28px; background: var(--card); }
.auth-box { width: 100%; max-width: 392px; }
.auth-box h2 { font-size: 23px; letter-spacing: -.02em; margin-bottom: 5px; }
.auth-box .lede { color: var(--muted); font-size: 14px; margin: 0 0 26px; }

/* ===================== mobile ===================== */
.mob-nav { display: none; }
.sticky-actions { display: none; }

@media (max-width: 1099px) {
  .row3 { grid-template-columns: 1fr; }
}
@media (max-width: 899px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; left: 0; top: 0; bottom: 0; width: 264px; z-index: 50;
    transform: translateX(-100%); transition: transform var(--t); height: 100%;
  }
  .side.open { transform: none; }
  .side-scrim { position: fixed; inset: 0; background: rgba(11,26,46,.4); z-index: 49; }
  .page { padding: var(--s4); padding-bottom: 88px; }
  .row2 { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-brand { padding: 28px 24px; }
  .auth-brand h2 { font-size: 23px; margin: 16px 0 8px; }
  .auth-brand ul, .auth-brand .foot, .auth-brand p { display: none; }

  /* Bottom tab bar replaces the sidebar */
  .mob-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .mob-nav a {
    flex: 1; text-align: center; padding: 9px 4px 8px; font-size: 10.5px; color: var(--muted);
    display: flex; flex-direction: column; align-items: center; gap: 3px;
  }
  .mob-nav a:hover { text-decoration: none; }
  .mob-nav a .ico { font-size: 17px; }
  .mob-nav a.on { color: var(--brand); font-weight: 600; }
  .mob-nav a.post .ico {
    background: var(--brand); color: #fff; width: 34px; height: 34px; border-radius: 50%;
    display: grid; place-items: center; margin-top: -12px; box-shadow: var(--shadow);
  }

  .sticky-actions {
    display: flex; gap: var(--s2); position: fixed; left: 0; right: 0; bottom: 56px;
    background: #fff; border-top: 1px solid var(--line); padding: 10px var(--s4); z-index: 44;
  }
  .sticky-actions .btn { flex: 1; }

  .kpis { grid-template-columns: 1fr 1fr; gap: var(--s3); }
  .kpi { padding: 12px 14px; }
  .kpi .v { font-size: 20px; margin-top: 4px; }
  .modal { max-width: none; max-height: 92vh; border-radius: var(--r-card) var(--r-card) 0 0; align-self: flex-end; }
  .overlay { padding: 0; align-items: flex-end; }
  .drawer { max-width: none; }
  .toasts { left: var(--s4); right: var(--s4); bottom: 118px; }
  .toast { max-width: none; }

  /* Tables become cards. Never a horizontally scrolling table on a phone. */
  .tbl.cards, .tbl.cards thead { display: block; }
  .tbl.cards thead { display: none; }
  .tbl.cards tbody, .tbl.cards tr, .tbl.cards td { display: block; width: 100%; }
  .tbl.cards tr {
    border: 1px solid var(--line); border-radius: var(--r-card); margin: 0 0 var(--s3);
    padding: 12px 14px; background: #fff;
  }
  .tbl.cards td { border: none; padding: 3px 0; display: flex; justify-content: space-between; gap: var(--s3); }
  .tbl.cards td::before {
    content: attr(data-label); font-size: 11.5px; color: var(--muted); font-weight: 500;
    text-transform: uppercase; letter-spacing: .04em;
  }
  .tbl.cards td[data-label=""]::before { content: none; }
  .tbl.cards td.head { font-weight: 600; font-size: 15px; color: var(--ink); padding-bottom: 6px; }
  .tbl.cards .num { text-align: right; }
}

@media print {
  .side, .topbar, .mob-nav, .sticky-actions, .btn, .filters { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  body { background: #fff; }
}
