/* tally.css — the redesigned Tally design system.
   Spec: "Tally App Redesign.dc.html" handoff. DM Sans throughout, navy
   sidebar, ink #232E42, green #2E9E6B. Legacy var names are remapped at
   the bottom so datatable.css (the dt2 grid) inherits the rebrand. */

:root {
  /* ── Redesign tokens ── */
  --ink: #232E42;
  --ink-hover: #2E3B54;
  --sidebar: #1B2432;
  --sidebar-active: #26314A;
  --sidebar-rule: #2A3348;
  --sidebar-text: #9AA6BC;
  --sidebar-org: #C4CCDA;
  --sidebar-user: #8992A3;
  --sidebar-signout: #6B7690;

  --green: #2E9E6B;
  --green-dark: #257F56;
  --green-on-dark: #56C493;
  --green-tint: #EAF5F0;
  --green-ink: #1E7A4E;

  --amber-tint: #FBF1DE;
  --amber-ink: #8A6D1E;
  --amber-ink-alt: #7A5A1E;

  --red: #D9534F;
  --red-ink: #C0392B;

  --page-bg: #F7F8F9;
  --card-bg: #ffffff;
  --card-border: #E3E7ED;
  --row-divider: #F0F2F5;
  --input-border: #DCE1E8;
  --input-bg: #FBFBFC;
  --chart-neutral: #C8D2DF;
  --chart-track: #F0F2F5;
  --chart-muted-bar: #DCE6E1;
  --table-head-bg: #FAFBFC;
  --tabs-bg: #EDEFF2;

  --text-muted: #7A8699;
  --text-light: #8992A3;

  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--page-bg);
  font-family: var(--font);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-dark); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--chart-neutral); border-radius: 4px; }

/* ── Shell ────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px; flex-shrink: 0; background: var(--sidebar);
  display: flex; flex-direction: column; justify-content: space-between;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 28px 24px 20px; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.brand .wordmark {
  font-size: 26px; font-weight: 800; letter-spacing: -0.02em;
  color: #fff; line-height: 1;
}
.brand .bars { display: flex; flex-direction: column; gap: 3px; width: 28px; }
.brand .bars span { height: 3px; background: var(--green-on-dark); border-radius: 1.5px; }

.nav { display: flex; flex-direction: column; padding: 8px 12px; gap: 2px; }
.nav a {
  display: block; width: 100%; text-align: left;
  padding: 11px 16px 11px 19px; border-radius: 6px;
  font-size: 14px; font-weight: 500; color: var(--sidebar-text);
  border-left: 3px solid transparent;
}
.nav a:hover { color: #fff; }
.nav a.active {
  background: var(--sidebar-active); color: #fff; font-weight: 700;
  border-left: 3px solid var(--green-on-dark); padding-left: 16px;
}

.sidebar .foot {
  padding: 20px 24px; border-top: 1px solid var(--sidebar-rule);
  display: flex; flex-direction: column; gap: 4px;
}
.sidebar .foot .org { font-size: 13px; color: var(--sidebar-org); font-weight: 500; }
.sidebar .foot .who { font-size: 13px; color: var(--sidebar-user); }
.sidebar .foot a { font-size: 13px; color: var(--sidebar-signout); margin-top: 6px; }
.sidebar .foot a:hover { color: var(--sidebar-text); }

.main { flex: 1; padding: 48px 56px 80px; min-width: 0; }

/* ── Typography ───────────────────────────────────────────────────── */
h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
h2 { font-size: 17px; font-weight: 700; color: var(--ink); margin-top: 30px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 20px; margin-bottom: 32px; }
.sub { display: none; } /* the redesign cuts explanatory subtext app-wide */
.small { font-size: 12.5px; }
.muted { color: var(--text-muted); }
.mono { font-variant-numeric: tabular-nums; }

/* ── Cards / panels ───────────────────────────────────────────────── */
.panel {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 14px; padding: 26px 28px; margin-bottom: 20px;
}
.panel-title { font-size: 17px; font-weight: 700; color: var(--ink); margin-bottom: 14px; }
.panel-note { font-size: 13.5px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.5; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ── KPI cards ────────────────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 24px; }
.kpi {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 14px; padding: 24px 26px;
  display: flex; flex-direction: column; gap: 14px;
}
.kpi .label {
  font-size: 12px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-light);
}
.kpi .value { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; color: var(--ink); }
.kpi .delta { font-size: 14px; color: var(--text-muted); font-weight: 500; }
.kpi .delta.pos { color: var(--green); font-weight: 700; }
.kpi .delta.neg { color: var(--red-ink); font-weight: 700; }

/* ── Buttons & inputs ─────────────────────────────────────────────── */
button, .btn {
  font-family: var(--font); font-size: 13px; font-weight: 600;
  height: 40px; padding: 0 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--input-border); background: #fff; color: var(--ink);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--table-head-bg); }
button.primary, .btn.primary {
  background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 700;
}
button.primary:hover, .btn.primary:hover { background: var(--ink-hover); border-color: var(--ink-hover); }
button:disabled { opacity: 0.5; cursor: default; }
button.tiny { height: 32px; padding: 0 12px; font-size: 12px; border-radius: 6px; }

select, input[type="text"], input[type="number"], input[type="email"],
input[type="password"], input[type="month"], input[type="date"] {
  font-family: var(--font); font-size: 14px; height: 42px; padding: 0 14px;
  border: 1px solid var(--input-border); border-radius: 8px;
  background: #fff; color: var(--ink);
}
input[type="checkbox"] { accent-color: var(--green); width: 15px; height: 15px; }
select:focus, input:focus { outline: 2px solid var(--green-tint); border-color: var(--green); }

.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.flash { font-size: 13px; font-weight: 600; }
.flash.ok { color: var(--green-ink); }
.flash.err { color: var(--red-ink); }

/* ── Pills & badges ───────────────────────────────────────────────── */
.badge, .pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; border-radius: 100px; padding: 4px 11px;
  background: var(--row-divider); color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.03em;
}
.badge.green, .pill.green { background: var(--green-tint); color: var(--green-ink); }
.badge.citron, .pill.amber { background: var(--amber-tint); color: var(--amber-ink); }
.badge.red, .pill.red { background: #FBEAEA; color: var(--red-ink); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 16px;
  background: var(--green-tint); color: var(--green-ink); border-radius: 8px;
  font-size: 13px; font-weight: 700; text-transform: none; letter-spacing: 0;
}
.status-pill.warn { background: var(--amber-tint); color: var(--amber-ink); }
.status-pill.bad { background: #FBEAEA; color: var(--red-ink); }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ── Tables ───────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; padding: 12px 14px; font-size: 12px; font-weight: 700;
  color: var(--text-light); letter-spacing: 0.04em; text-transform: uppercase;
  border-bottom: 1px solid var(--card-border); background: transparent;
}
td { padding: 14px; border-bottom: 1px solid var(--row-divider); color: var(--ink); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 800; border-bottom: none; border-top: 1px solid var(--card-border); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--table-head-bg); }
.panel > table:first-child th:first-child, .panel > table th:first-child { padding-left: 0; }
.panel > table td:first-child { padding-left: 0; }
.panel > table th:last-child, .panel > table td:last-child { padding-right: 0; }

/* Flush tables inside a bordered card (header strip like the spec) */
.panel.flush { padding: 0; overflow: hidden; }
.panel.flush .panel-title { padding: 20px 26px; margin: 0; border-bottom: 1px solid var(--row-divider); }
.panel.flush table th { background: var(--table-head-bg); padding: 12px 26px; }
.panel.flush table td { padding: 14px 26px; }

/* ── Segmented tabs ───────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 6px; background: var(--tabs-bg); padding: 5px;
  border-radius: 10px; width: fit-content; margin-bottom: 22px; flex-wrap: wrap;
}
.tabs button {
  height: 38px; padding: 0 18px; background: none; border: none;
  border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--text-muted);
}
.tabs button:hover { background: rgba(255, 255, 255, 0.5); }
.tabs button.on {
  background: #fff; color: var(--ink); font-weight: 700;
  box-shadow: 0 1px 2px rgba(30, 40, 60, 0.08);
}

/* ── Prominent selector bar (Accounting Rules) ────────────────────── */
.selector-bar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 14px; padding: 18px 24px; gap: 20px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.selector-bar .lab {
  font-size: 13px; font-weight: 700; color: var(--text-light);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.selector-bar select.big {
  height: 48px; border: 1px solid var(--chart-neutral); border-radius: 9px;
  padding: 0 18px; font-size: 17px; font-weight: 700; background: var(--input-bg);
  min-width: 220px;
}

/* ── Definition grids (key fields / booking) ──────────────────────── */
.def-grid { display: grid; gap: 20px 24px; font-size: 14px; }
.def-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.def-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.def-grid .k {
  color: var(--text-light); font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px;
}
.def-grid .v { color: var(--ink); font-weight: 600; }
.def-grid .v.unset { color: var(--text-muted); font-weight: 500; }

/* ── Rule rows (list-in-card) ─────────────────────────────────────── */
.rule-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 20px; padding: 22px 26px; border-bottom: 1px solid var(--row-divider);
  flex-wrap: wrap;
}
.rule-row:last-child { border-bottom: none; }
.rule-row .name { font-size: 16px; font-weight: 700; color: var(--ink); }
.rule-row .sentence { font-size: 14px; color: var(--text-muted); margin-top: 4px; }
.rule-row .right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.count-pill {
  font-size: 13px; font-weight: 700; color: var(--text-muted);
  background: var(--row-divider); padding: 6px 12px; border-radius: 100px;
}

/* ── Charts ───────────────────────────────────────────────────────── */
.legend { display: flex; align-items: center; gap: 16px; font-size: 12px; color: var(--text-muted); font-weight: 600; margin-bottom: 18px; }
.legend .key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--green); margin-right: 6px; vertical-align: -1px; }
.legend .key.tick { width: 2px; height: 12px; border-radius: 0; background: var(--ink); }
.legend .key.sched { background: var(--chart-muted-bar); }
.legend .key.out { background: var(--red); }

.bars { display: flex; flex-direction: column; gap: 22px; }
.bar-row .bar-head { display: flex; justify-content: space-between; font-size: 14px; font-weight: 700; color: var(--ink); margin-bottom: 8px; }
.bar-track { position: relative; height: 22px; background: var(--chart-track); border-radius: 6px; }
.bar-fill { position: absolute; left: 0; top: 0; height: 100%; background: var(--green); border-radius: 6px; }
.bar-tick { position: absolute; top: -4px; width: 2px; height: 30px; background: var(--ink); }

.colchart { display: flex; align-items: flex-end; gap: 18px; padding-top: 8px; }
.colchart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.colchart .plot { position: relative; width: 100%; height: 130px; display: flex; align-items: flex-end; }
.colchart .fill { width: 100%; background: var(--chart-muted-bar); border-radius: 4px 4px 0 0; }
.colchart .col.current .fill { background: var(--green); }
.colchart .budget { position: absolute; left: 0; right: 0; height: 2px; background: var(--ink); }
.colchart .lab { font-size: 11px; color: var(--text-light); font-weight: 600; }
.colchart .col.current .lab { color: var(--ink); font-weight: 700; }
.colchart .val { font-size: 11px; color: var(--text-muted); font-weight: 600; }

/* Waterfall */
.waterfall { display: flex; align-items: flex-end; gap: 14px; padding-top: 10px; overflow-x: auto; }
.waterfall .wcol { min-width: 74px; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.waterfall .wplot { position: relative; width: 100%; height: 170px; }
.waterfall .wbar { position: absolute; left: 8%; right: 8%; border-radius: 3px; }
.waterfall .wbar.anchor { background: var(--ink); }
.waterfall .wbar.up { background: var(--green); }
.waterfall .wbar.down { background: var(--red); }
.waterfall .wbar.sched { background: var(--chart-muted-bar); }
.waterfall .wval { font-size: 11px; font-weight: 700; color: var(--ink); }
.waterfall .wlab { font-size: 11px; color: var(--text-light); font-weight: 600; text-align: center; }

.recon-foot {
  display: flex; align-items: center; gap: 32px; flex-wrap: wrap;
  border-top: 1px solid var(--row-divider); margin-top: 22px; padding-top: 20px;
}
.recon-foot .item .k { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-light); }
.recon-foot .item .v { font-size: 18px; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; margin-top: 4px; }

/* ── Data-table cards (Data Tables list) ──────────────────────────── */
.table-card {
  display: block; background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 14px; padding: 22px 24px; position: relative; color: inherit;
}
.table-card:hover { border-color: var(--chart-neutral); color: inherit; }
.table-card .tc-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.table-card .tc-name { font-size: 16px; font-weight: 700; color: var(--ink); }
.table-card .tc-meta { font-size: 13px; color: var(--text-muted); }
.table-card .del-table {
  position: absolute; top: 14px; right: 14px; height: 28px; padding: 0 9px;
  font-size: 12px; border-radius: 6px; color: var(--text-muted);
}
.table-card .del-table:hover { color: var(--red-ink); border-color: var(--red); background: #fff; }

/* ── Period chips ─────────────────────────────────────────────────── */
.period-chip {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: 10px; padding: 10px 16px;
}
.period-chip strong { font-size: 14px; font-weight: 700; }
.period-chip.current { border-color: var(--green); }
.period-chip .cap {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-light);
}

/* ── Data-grid scroll wrapper (shared with dt2) ───────────────────── */
.data-scroll { overflow-x: auto; }
.data-grid { font-size: 13px; white-space: nowrap; }
.data-grid th.sortable { cursor: pointer; user-select: none; }
.filter-row th { padding: 4px 8px; border-bottom: 1px solid var(--row-divider); }
.filter-row input {
  width: 100%; min-width: 64px; height: 32px; font-size: 12px; padding: 0 8px;
  border: 1px solid var(--input-border); background: var(--input-bg); border-radius: 6px;
}
.data-grid td.future, .data-grid th.future { color: var(--text-light); }
.panel svg { max-width: 100%; display: block; }

/* ── Login gate ───────────────────────────────────────────────────── */
.auth-gate {
  position: fixed; inset: 0; z-index: 1000; background: var(--page-bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-gate[hidden] { display: none; }
.auth-card {
  width: 420px; max-width: 100%; background: #fff; border: 1px solid var(--card-border);
  border-radius: 16px; padding: 48px 44px; display: flex; flex-direction: column; gap: 28px;
  box-shadow: 0 1px 3px rgba(30, 40, 60, 0.06);
}
.auth-brand { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.auth-brand .wordmark { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; color: var(--ink); line-height: 1; }
.auth-brand .bars { display: flex; flex-direction: column; gap: 4px; width: 36px; }
.auth-brand .bars span { height: 4px; background: var(--green); border-radius: 2px; }
.auth-head { display: flex; flex-direction: column; gap: 6px; }
.auth-title { font-size: 24px; font-weight: 700; color: var(--ink); }
.auth-sub { font-size: 15px; color: var(--text-muted); }
.auth-form { display: flex; flex-direction: column; gap: 18px; }
.auth-field { display: flex; flex-direction: column; gap: 8px; }
.auth-field span { font-size: 13px; font-weight: 700; color: var(--ink); }
.auth-field em { font-weight: 500; color: var(--text-muted); font-style: normal; }
.auth-field input { height: 46px; font-size: 15px; background: var(--input-bg); }
.auth-gate:not(.is-signup) .auth-signup-only { display: none; }
.auth-submit {
  height: 50px; background: var(--ink); color: #fff; border: none; border-radius: 8px;
  font-size: 16px; font-weight: 700; justify-content: center; width: 100%;
}
.auth-submit:hover { background: var(--ink-hover); }
.auth-error { font-size: 13.5px; color: var(--red-ink); font-weight: 600; }
.auth-error[hidden] { display: none; }
.auth-toggle { text-align: center; font-size: 14px; color: var(--text-muted); }
.auth-toggle a { font-weight: 700; }
.auth-gate.is-checking .auth-card { opacity: 0; }

/* ── Tooltip (charts) ─────────────────────────────────────────────── */
.chart-tooltip {
  position: fixed; pointer-events: none; z-index: 30; display: none;
  background: var(--ink); color: #fff; font-size: 12.5px; padding: 8px 11px;
  border-radius: 6px; max-width: 260px; font-weight: 500;
}
.chart-tooltip .t-title { font-weight: 700; margin-bottom: 2px; }

/* ── dt2 host: the data-table view owns its pane ──────────────────── */
.main.dt2-host { padding: 0; }
.main.dt2-host .dt2 { height: 100vh; }

/* ── Legacy var remap: datatable.css inherits the rebrand ─────────── */
:root {
  --primary: #2E9E6B;
  --primary-light: #EAF5F0;
  --primary-mid: rgba(46, 158, 107, 0.12);
  --accent: #FBF1DE;
  --accent-ink: #8A6D1E;
  --accent-light: #FBF1DE;
  --bg: #F7F8F9;
  --surface: #ffffff;
  --border: #E3E7ED;
  --divider: #F0F2F5;
  --stone: #8992A3;
  --muted: #8992A3;
  --dark: #232E42;
  --rose: #C0392B;
  --rose-light: #FBEAEA;
  --charcoal: #232E42;
  --paper: #F7F8F9;
  --ice: #EAF5F0;
  --citron: #FBF1DE;
  --oxblood: #C0392B;
  --hairline: #F0F2F5;
  --ink-secondary: #7A8699;
  --font-display: 'DM Sans', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  --radius: 14px;
  --radius-sm: 8px;
}
