:root {
  --navy: #1f3864; --navy-2: #2e4a7d; --blue: #2e75b6; --ink: #1c2433; --muted: #6b7486;
  --line: #e4e8ef; --bg: #f4f6fa; --card: #ffffff; --green: #2f8f4e; --red: #c0392b;
  --amber: #fff2cc; --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.45; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 2px 0; }
h2 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.b { font-weight: 600; }
.neg { color: var(--red); }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #fff; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 0 8px 18px; }
.brand small { display: block; font-weight: 400; opacity: .7; font-size: 12px; }
.brand.big { color: var(--navy); font-size: 18px; padding: 0 0 18px; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 800; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.side nav a { color: #dfe7f5; padding: 9px 10px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.side nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
.side nav a:hover { background: var(--navy-2); text-decoration: none; }
.side nav a.on { background: #fff; color: var(--navy); font-weight: 600; }
.nav-h { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .55; margin: 14px 10px 4px; }
.me { border-top: 1px solid rgba(255,255,255,.15); padding: 12px 8px 0; display: flex; justify-content: space-between; align-items: center; }
.me a { color: #fff; } .me small { display: block; opacity: .6; }
.main { padding: 24px 28px 60px; min-width: 0; }
.menu-btn { display: none; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; }

/* components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(20,30,50,.04); }
.card.narrow { max-width: 560px; }
.card.empty { text-align: center; color: var(--muted); padding: 30px; }
.card-h { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.page-h { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { border-color: #c5cddb; text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #255f95; }
.btn.danger { color: var(--red); margin-top: 8px; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; margin-top: 8px; }
.link { background: none; border: 0; color: var(--blue); cursor: pointer; font: inherit; padding: 0; }
.me .link { color: #cfd9ec; }
.link.danger, .danger { color: var(--red); }
.flash { background: #e8f4ec; border: 1px solid #bfe0c9; color: #1e5e33; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.alert { background: #fdecea; border: 1px solid #f5c2bd; color: #8a2a20; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.pill { background: #e3f0e7; color: var(--green); border-radius: 99px; padding: 1px 8px; font-size: 11px; font-weight: 600; }
.inline { display: inline-block; margin-left: 10px; }

/* forms */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 10px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid #cfd6e2; border-radius: 8px; font: inherit; font-weight: 400; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #b8d4f0; border-color: var(--blue); }
input.n { text-align: right; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
label.check input { width: auto; margin: 0; }
.row3 { display: flex; gap: 12px; flex-wrap: wrap; }
.row3 > label { flex: 1 1 160px; }
.row3 > label.grow { flex: 2 1 240px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 4px; margin: 0 0 12px; }
legend { font-weight: 700; font-size: 12px; color: var(--muted); padding: 0 4px; }
.costgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.search { max-width: 320px; margin: 0 0 10px; }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filters select, .filters .search { width: auto; margin: 0; }
details.picker { margin: 0 0 12px; } details.picker summary { cursor: pointer; color: var(--blue); margin-bottom: 8px; }
details.picker .tbl { max-height: 320px; display: block; overflow-y: auto; }

/* period picker */
.period { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.seg { display: inline-flex; background: #e9edf4; border-radius: 9px; padding: 3px; flex-wrap: wrap; }
.seg button, .seg a { border: 0; background: none; padding: 6px 12px; border-radius: 7px; font: inherit; color: var(--ink); cursor: pointer; }
.seg .on { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }
.seg a:hover { text-decoration: none; }
.custom { display: flex; gap: 6px; align-items: center; }
.custom input { width: auto; margin: 0; padding: 6px 8px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpis.compact { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi.hero { border-top: 3px solid var(--blue); }
.kl { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kv { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kd { font-size: 12px; } .kd.up { color: var(--green); } .kd.down { color: var(--red); }

/* charts */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; } .grid2 { margin-bottom: 16px; }
.span2 { grid-column: span 2; }
.chart { position: relative; height: 260px; } .chart.tall { height: 320px; }

/* tables */
.scroll { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid #f0f2f6; vertical-align: top; }
.tbl tbody tr:hover { background: #f8fafd; }
.tbl .n { text-align: right; white-space: nowrap; }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: #f8fafd; }
.tbl tr.dim td { color: #a3abba; }
.tbl tr.cur { background: #f3faf5; }
.tbl .empty { text-align: center; color: var(--muted); padding: 20px; }
.tbl.pnl td.b { font-weight: 700; }
.tbl.pnl td:first-child { white-space: nowrap; }
.items span { display: block; font-size: 13px; }
.lines input { margin: 0; }
.lines td { padding: 4px 6px; }
.lines .prod { min-width: 260px; }
.lines .qty { width: 90px; } .lines .price { width: 110px; }
.day .card-h h2 { color: var(--navy); }

/* tabs, controls, small forms */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--navy); border-bottom-color: var(--blue); }
.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.controls .period { margin-bottom: 12px; }
.controls > .seg { margin-bottom: 12px; }
.seg button:disabled { opacity: .4; cursor: default; }
.seg-l { align-self: center; padding: 0 8px 0 6px; color: var(--muted); font-size: 12px; }
.inline-label { display: flex; align-items: center; gap: 8px; margin: 0; }
.inline-label select { width: auto; margin: 0; max-width: 420px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0 0 8px; }
.inline-form input { width: auto; flex: 1 1 140px; margin: 0; }
.inline-form .check { margin: 0; white-space: nowrap; }
.row-actions { display: flex; gap: 8px; align-items: center; }
.row-actions label { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; }
.row-actions input { margin: 0; width: auto; }
.reminder { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; background: #f3effc; border: 1px solid #ddd2f5;
  color: #4a2f8f; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.reminder span { flex: 1 1 260px; }
.reminder form { margin: 0; }
.tbl.pay td, .tbl.pay th { padding: 7px 6px; }
.payslip { max-width: 760px; }
.payslip .sum td { border-top: 2px solid var(--line); }
.payslip .big { font-size: 20px; }
.payslip h3 { margin: 18px 0 6px; font-size: 14px; }
.signs { display: flex; justify-content: space-between; margin-top: 48px; color: var(--muted); }
.signs span { border-top: 1px solid #999; padding-top: 6px; width: 40%; }
@media print {
  .side, .topbar, .ai-fab, .ai-panel, .no-print, .flash { display: none !important; }
  .shell { display: block; } .main { padding: 0; } .card { border: 0; box-shadow: none; }
}

/* undo bar */
.topbar { display: flex; align-items: center; gap: 10px; margin: -8px 0 12px; }
.undo-bar { display: flex; align-items: center; gap: 6px; margin-left: auto; min-width: 0; }
.undo-bar form { margin: 0; }
.undo-bar .btn:disabled { opacity: .45; cursor: default; }
.undo-what { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 360px; }

/* activity log */
.tbl.log td { vertical-align: top; }
.nowrap { white-space: nowrap; }
.entries { margin: 6px 0 0; padding-left: 18px; color: var(--muted); }
.pill.ai { background: #ede7f6; color: #5e35b1; }
.pill.grey { background: #eef0f4; color: var(--muted); }
.pager { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
summary { cursor: pointer; }

/* AI assistant */
.ai-fab { position: fixed; right: 20px; bottom: 20px; z-index: 30; background: var(--navy); color: #fff; border: 0;
  border-radius: 99px; padding: 12px 18px; font: inherit; font-weight: 700; cursor: pointer; box-shadow: 0 6px 20px rgba(20,30,60,.25); }
.ai-fab:hover { background: var(--navy-2); }
.ai-panel { position: fixed; right: 20px; bottom: 76px; z-index: 31; width: min(420px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 110px)); background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(20,30,60,.22); display: flex; flex-direction: column; }
.ai-panel[hidden] { display: none; }
.ai-panel header { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.ai-panel header #aiNew { margin-left: auto; }
.ai-msgs { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.ai-msg { padding: 9px 12px; border-radius: 12px; max-width: 92%; font-size: 13.5px; line-height: 1.5; overflow-x: auto; }
.ai-msg.user { align-self: flex-end; background: var(--blue); color: #fff; }
.ai-msg.assistant { align-self: flex-start; background: #f3f5f9; }
.ai-msg.thinking { color: var(--muted); font-style: italic; }
.ai-msg.error { background: #fdecea; color: #8a2a20; }
.ai-tbl { border-collapse: collapse; margin: 4px 0; font-size: 12.5px; }
.ai-tbl td { border-bottom: 1px solid #e3e7ee; padding: 3px 8px 3px 0; white-space: nowrap; }
.ai-changes { margin-top: 8px; padding-top: 8px; border-top: 1px dashed #cfd6e2; color: var(--green); font-size: 12.5px; }
.ai-panel form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.ai-panel textarea { margin: 0; resize: none; }

@media (max-width: 900px) {
  .undo-what { display: none; }
  .ai-fab { right: 12px; bottom: 12px; }
  .ai-panel { right: 8px; bottom: 64px; height: calc(100vh - 90px); }
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vw rgba(0,0,0,.35); }
  .menu-btn { display: inline-block; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 10px; font-size: 18px; margin-bottom: 10px; }
  .main { padding: 14px 16px 60px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  .lines .prod { min-width: 180px; }
  .lines { display: block; overflow-x: auto; }
}

/* payroll: several employees at once */
.bulk-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 10px; }
.tbl.bulk td { padding: 4px 6px; vertical-align: middle; }
.tbl.bulk td:nth-child(2) { cursor: pointer; white-space: nowrap; }
.tbl.bulk input, .tbl.bulk select { margin: 0; }
.tbl.bulk .rqty { width: 80px; display: inline-block; }
.tbl.bulk .rdate { width: 150px; }
.tbl.bulk tr:not(.on) td:nth-child(n+3) { opacity: .35; }
.tbl.bulk tr.on { background: #f5f9fe; }
.tbl.bulk tr.edited td:nth-child(2)::after { content: " ✎"; color: var(--blue); font-weight: 400; }

/* assistant voice */
.ai-voicebar { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--line);
  font-size: 12.5px; background: #fafbfd; }
.ai-voicebar .check { margin: 0; font-size: 12.5px; }
.ai-voicebar select { width: auto; margin: 0 0 0 auto; padding: 3px 6px; font-size: 12.5px; }
.ai-listening { display: flex; gap: 8px; align-items: center; padding: 8px 14px; background: #fdecea; color: #8a2a20; font-size: 13px; }
.ai-listening #aiHeard { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #5a2a20; }
.ai-listening .dot { width: 10px; height: 10px; border-radius: 50%; background: #e53935; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.btn.mic { padding: 8px 11px; font-size: 16px; }
.btn.mic.on { background: #e53935; border-color: #e53935; color: #fff; }
input[type=checkbox], input[type=radio] { width: auto; display: inline-block; margin: 0; }
.tbl.bulk td:first-child { width: 28px; }
.tbl.bulk .rkind { min-width: 200px; }
.tbl.bulk .rnote { min-width: 170px; }

[hidden] { display: none !important; }  /* a display rule must never un-hide something */
.ai-voiceopts { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding-top: 4px; }
.ai-voiceopts label { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; font-size: 12.5px; }
.ai-voiceopts select { width: auto; max-width: 230px; margin: 0; padding: 3px 6px; font-size: 12.5px; }
.ai-voiceopts input[type=range] { width: 90px; margin: 0; padding: 0; }
#aiVoiceMore { font-size: 12.5px; }

/* orders, payments, inventory */
.badge { background: #e53935; color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; padding: 1px 7px; margin-left: auto; }
.stock-alert { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; background: #fdecea; border: 1px solid #f5c2bd;
  color: #8a2a20; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.stock-alert span { flex: 1 1 280px; }
.pill.unpaid { background: #fdecea; color: #c0392b; }
.pill.part { background: #fff3cd; color: #946200; }
.pill.paid { background: #e3f0e7; color: var(--green); }
.pill.setup { background: #eef0f4; color: var(--muted); }
.pill.low { background: #fff3cd; color: #946200; }
.pill.out { background: #fdecea; color: #c0392b; }
.pill.ok { background: #e3f0e7; color: var(--green); }
.order-no { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--navy); font-weight: 600; white-space: nowrap; }
.paybox { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0; background: #fafbfd; }
.paybox .modes { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-bottom: 8px; }
.paybox .modes label { margin: 0; }
.paybox .row3 { margin-top: 4px; }
.quick { display: inline-flex; gap: 4px; }
.tbl.stock input, .tbl.stock select { margin: 0; }
.tbl.stock .n input { width: 110px; text-align: right; display: inline-block; }
.amount-big { font-size: 22px; font-weight: 700; }
/* owner withdrawals */
form.inline { display: inline; }
.inline-form select { width: auto; margin: 0; }
.inline-form .w-amt, .tbl.wd .wd-amt { flex: 0 1 110px; width: 110px; }
.tbl.wd td { padding: 4px 6px; vertical-align: middle; }
.tbl.wd input, .tbl.wd select { margin: 0; }
.tbl.wd .wd-kind { min-width: 140px; }
