:root {
  --brand: #4f46e5; --brand-2: #6366f1; --brand-soft: #eef2ff; --brand-ink: #3730a3;
  --bg: #f5f6fa; --surface: #ffffff; --surface-2: #f9fafb; --border: #e5e7eb; --border-strong: #d1d5db;
  --text: #111827; --text-2: #4b5563; --muted: #6b7280;
  --good: #047857; --good-bg: #ecfdf5; --warn: #b45309; --warn-bg: #fffbeb; --bad: #b91c1c; --bad-bg: #fef2f2; --info: #1d4ed8; --info-bg: #eff6ff;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px; --sidebar: 248px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --brand: #818cf8; --brand-2: #6366f1; --brand-soft: #1e1b4b; --brand-ink: #c7d2fe;
  --bg: #0f1117; --surface: #171a23; --surface-2: #1d2130; --border: #2a2f3d; --border-strong: #394052;
  --text: #f3f4f6; --text-2: #c3c7d1; --muted: #9097a6;
  --good: #34d399; --good-bg: #052e22; --warn: #fbbf24; --warn-bg: #2d2006; --bad: #f87171; --bad-bg: #2e0f12; --info: #93c5fd; --info-bg: #0e1d36;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.app.collapsed { --sidebar: 64px; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 14px 12px; border-bottom: 1px solid var(--border); }
.brand .logo { width: 36px; height: 36px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), #8b5cf6); color: #fff; display: grid; place-items: center; font-weight: 800; flex: none; }
.brand .t1 { font-weight: 700; } .brand .t2 { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.brand .collapse-btn { margin-left: auto; }
.nav { padding: 8px; flex: 1; }
.nav-group { margin-bottom: 2px; }
.nav-head { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; color: var(--text-2); font: inherit; font-weight: 600; border-radius: 8px; cursor: pointer; text-align: left; }
.nav-head:hover { background: var(--surface-2); }
.nav-head .ico, .nav-link .ico { width: 20px; text-align: center; flex: none; font-size: 15px; }
.nav-head .chev { margin-left: auto; font-size: 10px; transition: transform .15s; color: var(--muted); }
.nav-group.open .chev { transform: rotate(90deg); }
.nav-items { display: none; padding: 2px 0 6px 28px; }
.nav-group.open .nav-items { display: block; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 7px; color: var(--text-2); font-size: 13.5px; }
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.active, .nav-head.active { background: var(--brand-soft); color: var(--brand-ink); }
.app.collapsed .nav-items, .app.collapsed .brand .t, .app.collapsed .nav-head .lbl, .app.collapsed .nav-head .chev, .app.collapsed .side-foot { display: none; }
.side-foot { padding: 10px 14px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--border); }

.main { 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 20px; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar .search { position: relative; flex: 1; max-width: 520px; }
.topbar .search input { width: 100%; padding-left: 34px; }
.topbar .search .s-ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.15); max-height: 420px; overflow: auto; padding: 6px; }
.search-results .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 6px 8px 2px; }
.search-results a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--text); }
.search-results a:hover { background: var(--surface-2); text-decoration: none; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.online { font-size: 12px; color: var(--good); display: flex; align-items: center; gap: 6px; }
.online::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.online.off { color: var(--bad); }
.icon-btn { position: relative; border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 36px; height: 36px; border-radius: 9px; cursor: pointer; display: grid; place-items: center; font-size: 16px; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .dot { position: absolute; top: -4px; right: -4px; background: #ef4444; color: #fff; font-size: 10px; min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.user-chip:hover { border-color: var(--border); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.user-chip .n { font-weight: 600; font-size: 13px; line-height: 1.1; } .user-chip .r { font-size: 11.5px; color: var(--muted); }
.dropdown { position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.15); min-width: 280px; padding: 6px; z-index: 50; }
.dropdown a, .dropdown button.dd-item { display: flex; gap: 8px; align-items: center; width: 100%; padding: 8px 10px; border-radius: 7px; color: var(--text); background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }
.dropdown a:hover, .dropdown button.dd-item:hover { background: var(--surface-2); text-decoration: none; }
.content { padding: 20px; max-width: 1500px; width: 100%; }

/* ---------- page bits ---------- */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card-h .actions { margin-left: auto; display: flex; gap: 6px; }
.card-b { padding: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .l { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi a { color: inherit; } .kpi a:hover { text-decoration: none; }
.chart-box { position: relative; height: 280px; }

/* ---------- forms ---------- */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; outline: none; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); }
input[readonly] { background: var(--surface-2); }
textarea { resize: vertical; min-height: 60px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
label.f.req > span::after { content: " *"; color: var(--bad); }
label.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.form-grid > * { min-width: 0; }
.form-grid input:not([type=checkbox]), .form-grid select, .form-grid textarea { width: 100%; }
.form-grid .w2 { grid-column: span 2; } .form-grid .w4 { grid-column: 1 / -1; }
.form-sec { grid-column: 1 / -1; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px dashed var(--border); padding-bottom: 4px; margin-top: 6px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
:root[data-theme="dark"] .btn.primary { color: #0f1117; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; border-radius: 7px; }
.btn.ghost { border-color: transparent; background: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.toolbar input[type=search] { min-width: 220px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; font: inherit; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 9px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; cursor: default; position: sticky; top: 0; }
.tbl th.sortable { cursor: pointer; } .tbl th.sortable:hover { color: var(--text); }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border); }
.tbl .acts { white-space: nowrap; text-align: right; }
.tbl .acts .btn { margin-left: 4px; }
.tbl.compact td, .tbl.compact th { padding: 6px 10px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 8px; padding: 10px 16px; font-size: 12.5px; color: var(--muted); }
.pager .btn { margin-left: 2px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand-ink); border-color: transparent; }

/* ---------- document editor ---------- */
.items-tbl { width: 100%; border-collapse: collapse; }
.items-tbl th { font-size: 11.5px; color: var(--muted); text-transform: uppercase; font-weight: 600; padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.items-tbl td { padding: 5px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
.items-tbl input, .items-tbl select { width: 100%; padding: 6px 7px; }
.items-tbl input.n { text-align: right; }
.items-tbl .meta { font-size: 11px; color: var(--muted); padding: 2px 2px 0; }
.items-tbl td.amt { text-align: right; padding-top: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals { width: 100%; max-width: 380px; margin-left: auto; }
.totals td { padding: 5px 0; } .totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.totals tr.grand td { font-size: 18px; font-weight: 750; border-top: 2px solid var(--border); padding-top: 9px; }
.totals input { width: 120px; text-align: right; padding: 4px 8px; }

/* combobox */
.combo { position: relative; }
.combo-list { position: fixed; z-index: 300; max-height: 300px; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; box-shadow: 0 12px 30px rgba(0,0,0,.18); padding: 4px; }
.combo-list .opt { padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.combo-list .opt .sub { font-size: 11.5px; color: var(--muted); }
.combo-list .opt.hl, .combo-list .opt:hover { background: var(--brand-soft); }
.combo-list .opt.add { color: var(--brand); font-weight: 600; border-top: 1px solid var(--border); margin-top: 3px; }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,17,23,.5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 760px; box-shadow: 0 25px 60px rgba(0,0,0,.3); border: 1px solid var(--border); }
.modal.sm { max-width: 460px; } .modal.lg { max-width: 1040px; }
.modal-h { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-h .x { margin-left: auto; }
.modal-b { padding: 18px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: 9px; box-shadow: 0 8px 20px rgba(0,0,0,.25); max-width: 380px; animation: tin .2s ease; }
.toast.err { background: #991b1b; } .toast.ok { background: #065f46; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--brand) 25%, transparent), transparent), var(--bg); }
.login { width: 100%; max-width: 380px; padding: 28px; }
.login .logo { width: 48px; height: 48px; border-radius: 12px; background: linear-gradient(135deg, var(--brand), #8b5cf6); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 18px; margin-bottom: 14px; }
.login form { display: grid; gap: 12px; margin-top: 18px; }

/* attendance grid */
.att-btns { display: inline-flex; gap: 4px; }
.att-btns button { width: 34px; height: 30px; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 700; font-size: 12px; color: var(--text-2); }
.att-btns button.on[data-s=P] { background: var(--good-bg); color: var(--good); border-color: var(--good); }
.att-btns button.on[data-s=A] { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.att-btns button.on[data-s=H] { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.att-btns button.on[data-s=L], .att-btns button.on[data-s=WO] { background: var(--info-bg); color: var(--info); border-color: var(--info); }
.month-grid td, .month-grid th { padding: 4px 5px !important; text-align: center; font-size: 12px; }
.month-grid td.P { color: var(--good); font-weight: 700; } .month-grid td.A { color: var(--bad); font-weight: 700; } .month-grid td.H { color: var(--warn); font-weight: 700; } .month-grid td.L, .month-grid td.WO { color: var(--info); }

/* kanban for leads */
.kanban { display: grid; grid-template-columns: repeat(6, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.kcol { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 200px; }
.kcol h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; display: flex; justify-content: space-between; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 10px; margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow); }
.kcard:hover { border-color: var(--brand); }
.kcard .t { font-weight: 600; } .kcard .m { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ---------- print ---------- */
.print-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.paper { background: #fff; color: #111; width: 210mm; min-height: 280mm; margin: 0 auto; padding: 10mm; box-shadow: 0 4px 24px rgba(0,0,0,.15); font-size: 12px; }
.paper * { color: #111; }
.paper table { width: 100%; border-collapse: collapse; }
.paper .bx { border: 1px solid #333; }
.paper .bx td, .paper .bx th { border: 1px solid #333; padding: 4px 6px; vertical-align: top; }
.paper th { background: #f1f1f1 !important; font-size: 11px; text-align: left; }
.paper .title { text-align: center; font-size: 15px; font-weight: 800; letter-spacing: .08em; padding: 4px; border: 1px solid #333; border-bottom: 0; }
.paper .co-name { font-size: 20px; font-weight: 800; }
.paper .r { text-align: right; } .paper .c { text-align: center; }
.paper .sign { height: 60px; }
@media print {
  @page { size: A4; margin: 8mm; }
  body { background: #fff; }
  .sidebar, .topbar, .print-toolbar, #toasts, .no-print { display: none !important; }
  .app { display: block; } .content { padding: 0; max-width: none; }
  .paper { box-shadow: none; width: auto; min-height: 0; padding: 0; margin: 0; }
  .card { box-shadow: none; border: 0; }
  .tbl th { position: static; }
}

/* ---------- responsive ---------- */
.menu-btn { display: none; }
.save-bar { position: sticky; bottom: 0; margin-top: 16px; padding: 12px 0; background: var(--bg); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--border); z-index: 5; }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .app.mobile-open .sidebar { transform: none; }
  .menu-btn { display: grid; }
  .brand .collapse-btn { display: none; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  .content { padding: 14px 12px; }
  .topbar { padding: 8px 12px; }
  .user-chip .n, .user-chip .r, .online { display: none; }
  .paper { width: 100%; padding: 12px; }
  .save-bar #footInfo { display: none; }
  .save-bar .btn { flex: 1; }
  .main { overflow-x: clip; }
}
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } .form-grid .w2 { grid-column: auto; } }

/* ---------- attention: blinking red on the field to fill ---------- */
@keyframes attnBlink { 0%, 100% { border-color: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,.45); } 50% { border-color: #fca5a5; box-shadow: 0 0 0 1px rgba(239,68,68,.12); } }
input.attn, select.attn, textarea.attn,
.content input:focus:not([type=checkbox]):not([type=search]):not(#gsearch), .content select:focus, .content textarea:focus,
.modal input:focus:not([type=checkbox]), .modal select:focus, .modal textarea:focus { border-color: #ef4444 !important; animation: attnBlink 1s ease-in-out infinite; outline: none; }
@media (prefers-reduced-motion: reduce) { input.attn, select.attn, textarea.attn, .content input:focus, .content select:focus, .modal input:focus { animation: none; box-shadow: 0 0 0 3px rgba(239,68,68,.45); } }

/* ---------- low stock rows ---------- */
.tbl tr.low-row td { background: var(--bad-bg) !important; }
.tbl tr.low-row td:first-child { box-shadow: inset 4px 0 0 #ef4444; }
.tbl tr.low-row a { color: var(--bad); font-weight: 650; }
.min-inp { width: 80px; text-align: right; padding: 4px 6px; }
.doc-time { font-size: 11.5px; color: var(--muted); }
.qr-box img, .qr-box svg { width: 110px; height: 110px; display: block; }
.qr-box.qr-sm img, .qr-box.qr-sm svg { width: 64px; height: 64px; }
