/* Crook Books — one stylesheet, no build step.
   Brand: Crook Marketing / Weft. Deep teal ground for chrome, lime as the accent.
   Lime is paint only (fills, markers); as text it is the darker --lime-ink. */

@font-face { font-family: "Barlow"; font-weight: 400; font-display: swap; src: url("../fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-display: swap; src: url("../fonts/barlow-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-display: swap; src: url("../fonts/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 700; font-display: swap; src: url("../fonts/barlow-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Archivo Black"; font-weight: 400; font-display: swap; src: url("../fonts/archivo-black-latin-400-normal.woff2") format("woff2"); }

:root {
  --ink: #0F2B2B;
  --teal: #163B3B;
  --teal-2: #1F4B4B;
  --teal-3: #2A5C5C;
  --lime: #AED82E;
  --lime-2: #C2EA4E;
  --lime-ink: #4A6510;
  --bg: #F3F5F1;
  --surface: #FFFFFF;
  --surface-2: #F8FAF7;
  --border: #D8DFDA;
  --border-strong: #B9C4BF;
  --text: #17302F;
  --muted: #566664;
  --faint: #8A9895;
  --danger: #A8261B;
  --danger-bg: #FDF1F0;
  --warn: #7A5300;
  --warn-bg: #FFF6E0;
  --ok: #2D6A1E;
  --ok-bg: #EEF7E8;
  --info-bg: #EAF3F3;
  --focus: #2E7D7D;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(15, 43, 43, 0.06), 0 1px 1px rgba(15, 43, 43, 0.04);
  --font: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sidebar: 232px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--teal-3); }
a:hover { color: var(--ink); }
h1, h2, h3 { color: var(--ink); line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 0.75rem; }
small, .muted { color: var(--muted); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--teal);
  color: #E6EFEC;
  padding: 18px 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; flex-direction: column; gap: 6px; padding: 4px 8px 10px; border-bottom: 1px solid var(--teal-2); }
.brand img.crook { width: 150px; height: auto; }
.brand .dba { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: #B9CBC6; }
.brand .dba img { width: 18px; height: 18px; }
.brand .weft { font-family: "Archivo Black", var(--font); letter-spacing: 0.1em; color: #DDE9E5; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .group { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: #8FB0A9; padding: 12px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  color: #E6EFEC; text-decoration: none; padding: 8px 10px; border-radius: var(--radius);
  font-weight: 500;
}
.nav a:hover { background: var(--teal-2); color: #fff; }
.nav a.active { background: var(--teal-2); color: #fff; box-shadow: inset 3px 0 0 var(--lime); }
.sidebar .foot { margin-top: auto; font-size: 0.8rem; color: #8FB0A9; padding: 0 10px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-weight: 600; color: var(--ink); }
.topbar .who { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; }
.topbar .who img { width: 28px; height: 28px; border-radius: 50%; }
.btn.menu-toggle { display: none; }
.content { padding: 24px; max-width: 1320px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head p { margin: 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 0.92rem;
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--teal-3); color: var(--ink); }
.btn-primary { background: var(--lime); border-color: var(--lime); color: var(--ink); }
.btn-primary:hover { background: var(--lime-2); border-color: var(--lime-2); }
.btn-dark { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-dark:hover { background: var(--teal-2); color: #fff; }
.btn-danger { color: var(--danger); border-color: #E4B4AF; }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.btn-link { border: none; background: none; padding: 4px 6px; color: var(--teal-3); font-weight: 600; }
.btn-sm { padding: 4px 10px; font-size: 0.85rem; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

/* ---------- Cards, alerts, badges ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card h2 { margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat .label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat .value { font-size: 1.6rem; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat .note { font-size: 0.85rem; color: var(--muted); }

.alert { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: #F1C5C0; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: #F2DFAE; }
.alert-ok { background: var(--ok-bg); color: var(--ok); border-color: #CFE6C2; }
.alert-info { background: var(--info-bg); color: var(--ink); border-color: #CFE2E2; }

.badge { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: #CFE6C2; }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: #F2DFAE; }
.badge-danger { background: var(--danger-bg); color: var(--danger); border-color: #F1C5C0; }
.badge-lime { background: #F1F8DC; color: var(--lime-ink); border-color: #DCEBB0; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label, .label { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 0.8rem; color: var(--muted); }
.field .error { font-size: 0.82rem; color: var(--danger); }
input[type=text], input[type=email], input[type=date], input[type=number], input[type=search],
input[type=password], select, textarea {
  font: inherit; font-size: 0.95rem; color: var(--text);
  padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: #fff; min-width: 0; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
input.num-input { text-align: right; font-variant-numeric: tabular-nums; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 0.92rem; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 0; }
legend { font-size: 0.82rem; font-weight: 600; color: var(--muted); padding: 0 4px; }

/* ---------- Data tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data th { text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 9px 12px; position: sticky; top: 0; }
table.data td { padding: 8px 12px; border-bottom: 1px solid #EDF1EE; vertical-align: top; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #FAFCF8; }
table.data th.num { text-align: right; }
table.data tr.inactive td { color: var(--faint); }
table.data td.indent-1 { padding-left: 32px; }
table.data td.indent-2 { padding-left: 52px; }
table.data td.indent-3 { padding-left: 72px; }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--border-strong); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Line-entry grid (journal entries) */
table.entry { width: 100%; border-collapse: collapse; }
table.entry th { font-size: 0.78rem; color: var(--muted); text-align: left; padding: 6px; border-bottom: 1px solid var(--border); }
table.entry td { padding: 4px 6px; border-bottom: 1px solid #EDF1EE; }
table.entry td.lineno { color: var(--faint); width: 32px; text-align: center; }
table.entry tfoot td { font-weight: 700; padding-top: 10px; border-bottom: none; }
.out-of-balance { color: var(--danger); }

/* ---------- Reports ---------- */
.report-toolbar { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; box-shadow: var(--shadow); }
.report-toolbar .field { min-width: 140px; }
.report-toolbar .field.narrow { min-width: 110px; flex: 0 0 auto; }
.report-toolbar .grow { flex: 1 1 auto; }
details.customize { width: 100%; }
details.customize summary { cursor: pointer; font-weight: 600; color: var(--teal-3); padding: 4px 0; }
details.customize .panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px 18px; padding: 12px 0 4px; }

.report-sheet { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 22px 22px 28px; overflow-x: auto; }
.report-head { text-align: center; margin-bottom: 16px; }
.report-head .company { font-weight: 600; color: var(--ink); }
.report-head .dba { font-size: 0.85rem; color: var(--muted); }
.report-head .title { font-size: 1.25rem; font-weight: 700; color: var(--ink); margin-top: 2px; }
.report-head .subtitle { color: var(--muted); }
table.report { border-collapse: collapse; margin: 0 auto; min-width: 560px; font-size: 0.9rem; }
table.report th { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); border-bottom: 1px solid var(--border-strong); padding: 6px 10px; text-align: right; white-space: nowrap; vertical-align: bottom; }
table.report th.label-col { text-align: left; }
table.report td { padding: 4px 10px; white-space: nowrap; }
table.report td.label { text-align: left; white-space: normal; min-width: 240px; }
table.report td.num a { color: inherit; text-decoration: none; }
table.report td.num a:hover { color: var(--teal-3); text-decoration: underline; }
table.report tr.section > td.label { font-weight: 600; color: var(--ink); padding-top: 10px; }
table.report tr.total td { font-weight: 600; }
table.report tr.total td.num { border-top: 1px solid var(--border-strong); }
table.report tr.grand td { font-weight: 700; color: var(--ink); }
table.report tr.grand td.num { border-top: 1px solid var(--ink); border-bottom: 3px double var(--ink); }
table.report tr.detail td { color: var(--text); }
table.report tr.group-head td { font-weight: 600; padding-top: 10px; }
table.report td .neg-red { color: var(--danger); }
table.report tr.level-1 td.label { padding-left: 26px; }
table.report tr.level-2 td.label { padding-left: 44px; }
table.report tr.level-3 td.label { padding-left: 62px; }
table.report tr.level-4 td.label { padding-left: 80px; }
table.report tr.level-5 td.label { padding-left: 98px; }
table.report tr.collapsed-row { display: none; }
.toggle { border: none; background: none; cursor: pointer; padding: 0 4px 0 0; color: var(--muted); font: inherit; }
.toggle::before { content: "▾"; display: inline-block; width: 1em; }
.toggle.closed::before { content: "▸"; }
table.report tr.txn td { font-weight: 400; }
table.report td.text { text-align: left; white-space: normal; max-width: 280px; }
.report-foot { margin-top: 16px; font-size: 0.8rem; color: var(--muted); text-align: center; }
table.report th.group-head { text-align: center; border-bottom: 1px solid var(--border); }
table.report th.text-col { text-align: left; }
table.report tr.section td.label, table.report tr.header td.label { font-weight: 600; color: var(--ink); }
table.report tr.begin td { color: var(--muted); font-style: italic; }
table.report tr.detail td.text a { color: var(--teal-3); }
table.report .sum { display: none; }
table.report tr.is-collapsed .sum { display: inline; }
table.report tr.is-collapsed .own { display: none; }
.report-actions { display: flex; flex-wrap: wrap; gap: 8px; }
details.save-report { margin: -4px 0 14px; }
details.save-report summary { cursor: pointer; font-weight: 600; color: var(--teal-3); display: inline-block; padding: 2px 0; }
details.save-report form { margin-top: 8px; }
table.report.wide { width: 100%; }
table.report.wide td.col-date, table.report.wide td.col-type, table.report.wide td.col-num,
table.report.wide td.col-due { white-space: nowrap; }
table.report.wide tr.header td.label, table.report.wide tr.total td.label,
table.report.wide tr.section td.label, table.report.wide tr.begin td.label { white-space: nowrap; }
table.report.wide td.label { min-width: 0; }
.report-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px 24px; }
.report-list a { font-weight: 600; text-decoration: none; }
.report-list p { margin: 2px 0 0; color: var(--muted); font-size: 0.88rem; }
.filters-grid select[multiple] { min-height: 92px; }

/* ---------- Misc ---------- */
/* Spacing utilities: the CSP forbids inline style attributes, so spacing lives here. */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-16 { margin-bottom: 16px; }
.w-auto, input.w-auto, select.w-auto { width: auto; }
.inline { display: inline; }
.list-inline { display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 0; margin: 0; list-style: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--lime); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 0.85rem; }
.kv dd { margin: 0; }
.toast { position: fixed; right: 18px; bottom: 18px; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,0.2); z-index: 100; max-width: 420px; }
.toast.error { background: var(--danger); }
.htmx-indicator { opacity: 0; transition: opacity 120ms ease-in; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--teal-3); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--teal); padding: 24px; }
.auth .panel { background: var(--surface); border-radius: 10px; padding: 32px 30px; width: 100%; max-width: 400px; box-shadow: 0 10px 40px rgba(0,0,0,0.25); text-align: center; }
.auth .panel img.crook { width: 210px; height: auto; margin-bottom: 4px; }
.auth .panel .dba { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.9rem; margin-bottom: 18px; }
.auth .panel .dba img { width: 18px; height: 18px; }
.auth .panel .weft { font-family: "Archivo Black", var(--font); letter-spacing: 0.1em; color: var(--teal-3); }
.auth .panel .btn { width: 100%; padding: 11px 14px; }
.auth .panel .or { margin: 14px 0; color: var(--faint); font-size: 0.85rem; }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; transform: translateX(-100%); transition: transform 160ms ease; z-index: 50; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,0.35); }
  .btn.menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar { padding: 10px 16px; }
  .report-sheet { padding: 14px; }
}

/* ---------- Print ---------- */
@media print {
  body { background: #fff; font-size: 11pt; }
  .sidebar, .topbar, .report-toolbar, .no-print, .toast, .page-head .actions, .toggle { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .report-sheet { border: none; box-shadow: none; padding: 0; }
  table.report { min-width: 0; width: 100%; }
  table.report thead { display: table-header-group; }
  table.report tr { page-break-inside: avoid; }
  table.report tr.collapsed-row { display: table-row; }
  a { color: inherit; text-decoration: none; }
}
