/* The Apex Loom business software. Brand: Loom Emerald, Imperial Cream, Zari Gold, Obsidian. */
:root {
  --emerald: #0F3B2E; --emerald-deep: #0A2A21; --emerald-soft: #e3eee9;
  --gold: #B8904A; --gold-light: #D2B274; --brass: #7A5C26;
  --cream: #F3ECDD; --parchment: #FAF6EC; --obsidian: #0E100F; --steel: #8A8F8C;
  --bg: #f6f3ea; --surface: #ffffff; --surface-2: #faf7f0; --border: #e4ddcc; --text: #17201c; --muted: #5f6b66;
  --ok: #1f7a4d; --ok-bg: #e2f3ea; --warn: #8a5a00; --warn-bg: #fdf1d8; --bad: #a2302a; --bad-bg: #fbe4e1; --info: #1d4f7a; --info-bg: #e1edf8;
  --radius: 10px; --shadow: 0 1px 2px rgba(15, 59, 46, .06), 0 4px 16px rgba(15, 59, 46, .05);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sidebar-w: 248px;
}
.theme-dark {
  --bg: #0e100f; --surface: #161b19; --surface-2: #1c2220; --border: #2a332f; --text: #ece6d8; --muted: #a5ada9;
  --emerald-soft: #183a2f; --ok-bg: #143628; --warn-bg: #3a2c10; --bad-bg: #3d1917; --info-bg: #152b40;
  --ok: #6fd3a0; --warn: #f0c46a; --bad: #f19a92; --info: #8cc3f3; --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14.5px; line-height: 1.5; color: var(--text); background: var(--bg); }
a { color: var(--emerald); text-decoration: none; }
.theme-dark a { color: var(--gold-light); }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.45rem; font-weight: 650; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: .98rem; font-weight: 650; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; vertical-align: -3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--emerald); color: #f3ecdd; display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 30; transition: transform .2s ease; }
.brand { padding: 18px 18px 14px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.brand-name { font-family: var(--serif); font-size: 1.12rem; letter-spacing: .08em; color: var(--gold-light); font-weight: 600; white-space: nowrap; }
.brand-sub { font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; color: rgba(243, 236, 221, .7); }
.nav { overflow-y: auto; padding: 8px 10px 16px; flex: 1; }
.nav-group { margin-top: 12px; }
.nav-title { font-size: .68rem; text-transform: uppercase; letter-spacing: .16em; color: rgba(243, 236, 221, .55); padding: 4px 10px; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 7px 10px; border-radius: 8px; color: #f3ecdd; font-size: .92rem; }
.nav a:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
.nav a.active { background: rgba(210, 178, 116, .18); color: #fff; box-shadow: inset 3px 0 0 var(--gold-light); }
.nav .count { margin-left: auto; background: var(--gold); color: var(--obsidian); border-radius: 999px; font-size: .72rem; padding: 0 7px; font-weight: 700; }
.sidebar-foot { padding: 12px 18px; border-top: 1px solid rgba(255, 255, 255, .08); font-size: .82rem; color: rgba(243, 236, 221, .75); }
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .page-title { font-weight: 650; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.search { display: flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; min-width: 260px; }
.search input { border: 0; background: transparent; outline: none; color: var(--text); width: 100%; font: inherit; }
.icon-btn { background: none; border: 0; color: var(--text); padding: 6px; border-radius: 8px; cursor: pointer; position: relative; display: inline-flex; align-items: center; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .dot { position: absolute; top: 0; right: -2px; background: var(--bad); color: #fff; border-radius: 999px; font-size: .65rem; padding: 0 5px; font-weight: 700; }
.menu-toggle { display: none; }
.content { padding: 22px 24px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 16px; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; color: var(--muted); max-width: 760px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sb-collapsed .sidebar { width: 64px; }
.sb-collapsed .main { margin-left: 64px; }
.sb-collapsed .nav-title, .sb-collapsed .nav a span, .sb-collapsed .brand-sub, .sb-collapsed .sidebar-foot, .sb-collapsed .nav .count { display: none; }
.sb-collapsed .brand-name { font-size: .9rem; letter-spacing: .06em; }
.sb-collapsed .nav a { justify-content: center; }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
form.actions { margin-bottom: 6px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: block; color: var(--text); }
a.kpi:hover { border-color: var(--gold); text-decoration: none; }
.kpi .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .value { font-size: 1.45rem; font-weight: 700; margin-top: 2px; }
.kpi .sub { font-size: .8rem; color: var(--muted); }
.kpi.warn { border-left: 4px solid var(--gold); }
.kpi.bad { border-left: 4px solid var(--bad); }
.kpi.good { border-left: 4px solid var(--ok); }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--emerald); background: var(--emerald); color: #fff; padding: 7px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.3; }
.btn:hover { background: var(--emerald-deep); text-decoration: none; color: #fff; }
.theme-dark .btn { color: #fff; }
.btn-secondary { background: var(--surface); color: var(--emerald); border-color: var(--border); }
.theme-dark .btn-secondary { color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); color: var(--emerald); border-color: var(--gold); }
.theme-dark .btn-secondary:hover { color: var(--text); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: var(--obsidian); }
.btn-gold:hover { background: var(--brass); color: #fff; }
.btn-danger { background: var(--bad); border-color: var(--bad); }
.btn-danger:hover { background: #7e231f; }
.btn-wa { background: #1f9e55; border-color: #1f9e55; }
.btn-wa:hover { background: #17803f; }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.swatch { display: inline-flex; vertical-align: middle; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--surface-2); font-weight: 650; position: sticky; top: 0; }
.table tr:last-child td { border-bottom: 0; }
.table .name { min-width: 230px; }
.table td.nowrap, .table td:first-child { white-space: nowrap; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.num, .table th.num { text-align: left; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tfoot td { font-weight: 700; background: var(--surface-2); }
.table .row-low { background: var(--warn-bg); }
.table .row-out { background: var(--bad-bg); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- toolbar, filters, tabs, pager ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.toolbar .field { margin: 0; }
.toolbar input, .toolbar select { min-width: 140px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 7px 12px; border-radius: 8px 8px 0 0; color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a.on { color: var(--emerald); box-shadow: inset 0 -2px 0 var(--gold); }
.theme-dark .tabs a.on { color: var(--gold-light); }
.tabs .n { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; font-size: .75rem; margin-left: 4px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: 10px; color: var(--muted); font-size: .88rem; flex-wrap: wrap; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
.field .help { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.field .errors { color: var(--bad); font-size: .82rem; margin-top: 3px; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad); }
input[type=text], input[type=number], input[type=email], input[type=password], input[type=date], input[type=url], input[type=search], input[type=tel], input[type=file], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-light); outline-offset: 0; border-color: var(--gold); }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--emerald); vertical-align: -3px; }
.check-row { display: flex; gap: 8px; align-items: center; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 0 0 16px; }
legend { font-weight: 700; padding: 0 6px; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.lines .line-row { display: grid; grid-template-columns: 2.4fr .7fr 1fr 1fr 40px; gap: 8px; align-items: end; margin-bottom: 8px; }
.lines .line-row .field { margin: 0; }
.totals { width: 100%; max-width: 380px; margin-left: auto; }
.totals td { padding: 4px 0; }
.totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.totals tr.grand td { font-weight: 800; font-size: 1.1rem; border-top: 2px solid var(--border); padding-top: 8px; }

/* ---------- detail ---------- */
dl.facts { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--muted); font-size: .88rem; }
dl.facts dd { margin: 0; word-break: break-word; white-space: pre-line; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 6px 0 6px 16px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; width: 8px; height: 8px; background: var(--gold); border-radius: 50%; position: absolute; left: -5px; top: 12px; }
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.steps .step { padding: 4px 10px; border-radius: 999px; font-size: .8rem; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.steps .step.done { background: var(--emerald-soft); color: var(--emerald); border-color: transparent; }
.theme-dark .steps .step.done { color: var(--gold-light); }
.steps .step.now { background: var(--gold); color: var(--obsidian); border-color: var(--gold); font-weight: 700; }

/* ---------- messages ---------- */
.messages { list-style: none; margin: 0 0 14px; padding: 0; }
.messages li { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-weight: 500; }
.messages .success { background: var(--ok-bg); color: var(--ok); }
.messages .error { background: var(--bad-bg); color: var(--bad); }
.messages .warning { background: var(--warn-bg); color: var(--warn); }
.messages .info { background: var(--info-bg); color: var(--info); }

/* ---------- charts ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--emerald); }
.theme-dark .chart .bar { fill: var(--gold-light); }
.chart .bar2 { fill: var(--gold); }
.chart .axis { stroke: var(--border); }
.chart text { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.legend .l1 { background: var(--emerald); }
.legend .l2 { background: var(--gold); }
.meter { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--emerald); padding: 20px; }
.auth-card { background: var(--parchment); color: var(--obsidian); border-radius: 14px; padding: 28px 30px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.auth-card .brand-name { color: var(--emerald); text-align: center; font-size: 1.5rem; }
.auth-card .brand-sub { color: var(--brass); text-align: center; margin-bottom: 18px; }
.auth-card .btn { width: 100%; justify-content: center; margin-top: 6px; }
.qr { background: #fff; padding: 10px; border-radius: 8px; display: inline-block; }
.qr svg { width: 180px; height: 180px; }
.code { font-family: Consolas, "Courier New", monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; border: 1px solid var(--border); word-break: break-all; }

/* ---------- print ---------- */
@media print {
  .sidebar, .topbar, .no-print, .form-actions, .messages { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; color: #000; font-size: 12px; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  a { color: #000; }
}

/* ---------- small screens ---------- */
@media (max-width: 980px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
  .nav-open .sidebar { transform: none; }
  .main, .sb-collapsed .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .search { min-width: 0; flex: 1; }
  .topbar { gap: 6px; padding: 8px 10px; }
  .topbar .spacer, .topbar [data-collapse] { display: none; }
  .nav-open .sidebar { box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  .nav-open .main::before { content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 25; }
  .topbar .page-title { display: none; }
  .content { padding: 16px 14px 60px; }
  .lines .line-row { grid-template-columns: 1fr 1fr; }
  dl.facts { grid-template-columns: 1fr; }
  .sb-collapsed .nav-title, .sb-collapsed .nav a span, .sb-collapsed .brand-sub, .sb-collapsed .sidebar-foot { display: initial; }
}
