:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-1-wash: rgba(42, 120, 214, 0.10);
  --series-2-wash: rgba(235, 104, 52, 0.10);
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --success-text: #006300;
  --card-shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-1-wash: rgba(57, 135, 229, 0.14);
    --series-2-wash: rgba(217, 89, 38, 0.14);
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #e66767;
    --success-text: #0ca30c;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-1-wash: rgba(57, 135, 229, 0.14);
  --series-2-wash: rgba(217, 89, 38, 0.14);
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #e66767;
  --success-text: #0ca30c;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--series-1); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 20px 64px; }

/* header */
header.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--border); margin-bottom: 24px;
}
header.site-header .brand { display: flex; align-items: center; }
header.site-header .brand-logo {
  height: 50pxpx; width: auto; display: block;
  /* logo's "Textile Mills Limited" text is navy — low contrast on the dark
     surface, so give it a light backing chip in dark mode only */
  background: transparent; border-radius: 6px; padding: 4px 8px; margin: -4px -8px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) header.site-header .brand-logo { background: #fcfcfb; }
}
:root[data-theme="dark"] header.site-header .brand-logo { background: #fcfcfb; }
header.site-header nav { display: flex; gap: 18px; }
header.site-header nav a {
  text-decoration: none; color: var(--text-secondary); font-size: 13.5px; font-weight: 600;
  padding: 6px 2px; border-bottom: 2px solid transparent;
}
header.site-header nav a.active, header.site-header nav a:hover { color: var(--text-primary); border-bottom-color: var(--series-1); }

.banner {
  background: linear-gradient(135deg, var(--series-1) 0%, #1c5cab 100%);
  color: #fff; border-radius: 12px; padding: 9px 16px; font-size: 12px; font-weight: 600;
  margin-bottom: 20px;
}

/* KPI tiles */
.kpi-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 24px; }
@media (max-width: 1000px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.stat-tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--card-shadow);
}
.stat-tile .label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.stat-tile .value-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.stat-tile .value { font-size: 20px; font-weight: 700; }
.stat-tile .delta { font-size: 12px; font-weight: 600; }
.stat-tile .delta.bad { color: var(--status-critical); }
.stat-tile .delta.good { color: var(--success-text); }
.stat-tile .spark { margin-top: 8px; display: block; }

/* cards */
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px 20px; box-shadow: var(--card-shadow); position: relative;
}
.card h3 { font-size: 13.5px; margin: 0 0 2px; }
.card .sub { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.full-row { margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: stretch; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
.grid-2 > .card { display: flex; flex-direction: column; }
.grid-2 > .card > .chart-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.support-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .support-row { grid-template-columns: 1fr; } }
.support-row > .card { display: flex; flex-direction: column; }
.support-row > .card > .chart-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 2px; background: currentColor; display: inline-block; border-radius: 2px; }
.legend i.dash { background: repeating-linear-gradient(to right, currentColor 0 4px, transparent 4px 7px); }

.chart-wrap { position: relative; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--text-primary); color: var(--surface-1); font-size: 11.5px;
  border-radius: 8px; padding: 8px 10px; box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  opacity: 0; transform: translate(-50%, -110%); transition: opacity .08s; white-space: nowrap;
}
.tooltip .t-title { font-weight: 700; margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 6px; }
.tooltip .t-row + .t-row { margin-top: 2px; }
.tooltip .t-key { width: 10px; height: 2px; border-radius: 2px; display: inline-block; }
.tooltip .t-val { font-weight: 700; }
.tooltip .t-name { color: var(--text-muted); }

/* AI insight panel */
.panel { border-radius: 12px; padding: 14px 16px; border: 1px solid var(--border); }
.panel.automation { background: var(--page); }
.panel.ai { background: var(--series-1-wash); border-color: color-mix(in srgb, var(--series-1) 35%, var(--border)); }
.panel h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px; margin: 0 0 8px;
  display: flex; align-items: center; gap: 6px; color: var(--text-secondary);
}
.panel.ai h4 { color: var(--series-1); }
.panel h4 .tag {
  font-size: 9.5px; font-weight: 700; padding: 1px 6px; border-radius: 5px;
  background: var(--text-muted); color: var(--surface-1); text-transform: uppercase;
}
.panel.ai h4 .tag { background: var(--series-1); }
.panel p { margin: 0 0 8px; font-size: 13px; line-height: 1.55; }
.driver-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 10px; margin: 3px 6px 3px 0; text-decoration: none; color: var(--text-primary);
}
.driver-chip:hover { border-color: var(--series-1); color: var(--series-1); }

/* voice — global floating button, on-load tooltip, answer popup */
.voice-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 30;
  width: 58px; height: 58px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--series-1); color: #fff; font-size: 24px; display: flex;
  align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(42,120,214,0.4);
  transition: transform .1s, background .15s;
}
.voice-fab:active, .voice-fab.recording { background: var(--status-critical); transform: scale(1.08); }

.voice-tooltip {
  position: fixed; right: 24px; bottom: 92px; z-index: 30; max-width: 240px;
  background: var(--text-primary); color: var(--surface-1); font-size: 12.5px; line-height: 1.5;
  border-radius: 10px; padding: 10px 30px 10px 12px; box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  opacity: 0; transform: translateY(6px); pointer-events: none; transition: opacity .15s, transform .15s;
}
.voice-tooltip.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.voice-tooltip-close {
  position: absolute; top: 6px; right: 8px; background: none; border: none; cursor: pointer;
  color: var(--surface-1); font-size: 15px; line-height: 1; opacity: .7; padding: 2px;
}
.voice-tooltip-close:hover { opacity: 1; }

/* chat-bubble panel — anchored above the fab, single latest exchange only */
.voice-chat {
  position: fixed; right: 24px; bottom: 92px; z-index: 30;
  width: 320px; max-width: calc(100vw - 48px); max-height: 60vh; overflow-y: auto;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 34px 14px 16px; box-shadow: 0 10px 32px rgba(0,0,0,0.28);
  opacity: 0; transform: translateY(8px) scale(.98); pointer-events: none;
  transition: opacity .15s, transform .15s;
}
.voice-chat.show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.voice-chat-close {
  position: absolute; top: 10px; right: 10px; background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 16px; line-height: 1; padding: 2px;
}
.voice-chat-close:hover { color: var(--text-primary); }
.voice-chat-processing { font-size: 13px; color: var(--text-secondary); font-style: italic; }
.voice-chat-section { margin-bottom: 12px; }
.voice-chat-section:last-child { margin-bottom: 0; }
.voice-chat .t-label { color: var(--text-muted); font-size: 10.5px; text-transform: uppercase; margin-bottom: 3px; letter-spacing: .3px; }
.voice-chat .t-text { font-size: 13.5px; line-height: 1.5; }
.voice-chat .t-text.muted { color: var(--text-secondary); }

/* tables */
table.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data-table th, table.data-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--grid); }
table.data-table thead th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }
table.data-table tbody tr:hover { background: var(--page); }
table.data-table tr.highlight { background: var(--series-2-wash); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.badge.outstanding { background: var(--status-warning); color: #2a2000; }
.badge.paid { background: var(--status-good); color: #fff; }

/* accounts tabs + forms */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab-btn {
  appearance: none; border: none; background: transparent; cursor: pointer;
  padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--text-secondary);
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: inherit;
}
.tab-btn.active { color: var(--series-1); border-bottom-color: var(--series-1); }
.ledger-section { display: none; }
.ledger-section.active { display: block; }

.section-toolbar { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.btn-add {
  padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer;
  background: var(--series-1); color: #fff; font-weight: 600; font-size: 13px;
}
.btn-add:hover { opacity: .9; }
.btn-edit {
  appearance: none; border: 1px solid var(--border); background: var(--surface-1); cursor: pointer;
  border-radius: 6px; width: 26px; height: 26px; font-size: 13px; color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-edit:hover { color: var(--series-1); border-color: var(--series-1); }

/* modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(11,11,11,0.45);
  align-items: center; justify-content: center; z-index: 20; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface-1); border-radius: 14px; padding: 20px 22px;
  max-width: 480px; width: 100%; max-height: 88vh; overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.modal h3 { margin: 0 0 14px; font-size: 16px; }
.modal-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.modal-form label { display: flex; flex-direction: column; font-size: 11.5px; color: var(--text-secondary); gap: 4px; }
.modal-form input, .modal-form select, .modal-form textarea {
  font: inherit; font-size: 13px; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--page); color: var(--text-primary);
}
.modal-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.modal-actions button {
  padding: 8px 18px; border-radius: 8px; border: none; font-weight: 600; font-size: 13px; cursor: pointer;
}
.modal-actions .btn-cancel { background: var(--page); color: var(--text-secondary); border: 1px solid var(--border); }
.modal-actions button[type="submit"] { background: var(--series-1); color: #fff; }
.modal-actions button:hover { opacity: .9; }

.foot-note {
  margin-top: 30px; font-size: 11.5px; color: var(--text-muted);
  border-top: 1px solid var(--border); padding-top: 14px; line-height: 1.6;
}

/* login page */
.login-body { min-height: 100vh; margin: 0; display: flex; align-items: center; justify-content: center; background: var(--page); }
.login-wrap { width: 100%; max-width: 360px; padding: 20px; }
.login-card { text-align: center; padding: 32px 28px; }
.login-logo {
  height: 50px; width: auto; margin-bottom: 18px;
  background: transparent; border-radius: 6px; padding: 4px 8px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .login-logo { background: #fcfcfb; }
}
:root[data-theme="dark"] .login-logo { background: #fcfcfb; }
.login-card h1 { font-size: 19px; margin: 0 0 4px; }
.login-card .sub { margin-bottom: 20px; }
.login-error {
  background: color-mix(in srgb, var(--status-critical) 12%, var(--surface-1));
  color: var(--status-critical); border: 1px solid color-mix(in srgb, var(--status-critical) 35%, var(--border));
  border-radius: 8px; padding: 8px 12px; font-size: 12.5px; margin-bottom: 14px; text-align: left;
}
.login-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--text-secondary); gap: 5px; }
.login-form input {
  font: inherit; font-size: 14px; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--page); color: var(--text-primary);
}
.login-form button {
  margin-top: 4px; padding: 10px 18px; border-radius: 8px; border: none;
  background: var(--series-1); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer;
}
.login-form button:hover { opacity: .9; }
