:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --brand: #2453c7; --brand-soft: #e8eefc; --good: #137a43; --good-soft: #e3f4ea;
  --bad: #b42318; --bad-soft: #fdecea; --warn: #9a6200; --warn-soft: #fff4dc;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input:disabled, textarea:disabled { background: #f2f3f6; color: var(--muted); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.btn { border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f8f9fb; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .logo { font-weight: 700; font-size: 16px; }
.topbar .logo span { color: var(--brand); }
.topbar nav { display: flex; gap: 4px; margin-left: 12px; }
.topbar nav a { padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--muted); }
.topbar nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.topbar .spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; }
.role-pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; background: var(--brand-soft); color: var(--brand); }
.role-pill.client { background: var(--warn-soft); color: var(--warn); }
.role-pill.team { background: var(--good-soft); color: var(--good); }

/* Bell */
.bell { position: relative; }
.bell .count { position: absolute; top: -4px; right: -4px; background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 4px; }
.notif-panel { position: absolute; right: 0; top: 42px; width: 380px; max-width: calc(100vw - 24px); max-height: 70vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.12); z-index: 30; }
.notif-panel header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.notif { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.notif.unread { background: var(--brand-soft); }
.notif time { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { color: var(--muted); margin: 0 0 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; }
.error { color: var(--bad); background: var(--bad-soft); padding: 8px 10px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }

/* Toolbar + stats */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }

/* Product table */
.table-wrap { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
tr.row { cursor: pointer; }
tr.row:hover td { background: #fafbff; }
td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }
.thumb { width: 44px; height: 44px; object-fit: contain; border-radius: 6px; background: #fff; border: 1px solid var(--line); }
.thumb.empty { display: grid; place-items: center; color: var(--muted); font-size: 10px; }
.pname { font-weight: 600; max-width: 320px; }
.sub { color: var(--muted); font-size: 12px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.muted { background: #eef0f4; color: var(--muted); }
.neg { color: var(--bad); font-weight: 600; }
.pos { color: var(--good); font-weight: 600; }
.empty-state { padding: 40px; text-align: center; color: var(--muted); }

/* Toggle */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #cfd4dc; border-radius: 99px; transition: .15s; cursor: pointer; }
.switch .slider:before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + .slider { background: var(--good); }
.switch input:checked + .slider:before { transform: translateX(18px); }
.switch input:disabled + .slider { cursor: default; opacity: .6; }

/* Drawer */
.overlay { position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 720px; max-width: 100vw; background: var(--bg); z-index: 50; display: flex; flex-direction: column; box-shadow: -10px 0 30px rgba(0,0,0,.15); }
.drawer-head { display: flex; gap: 14px; align-items: center; padding: 16px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.drawer-head img { width: 64px; height: 64px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.drawer-head h2 { margin: 0; font-size: 17px; }
.drawer-head .close { margin-left: auto; align-self: flex-start; }
.tabs { display: flex; gap: 2px; padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 12px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.scheme-inputs { display: flex; align-items: center; gap: 8px; }
.scheme-inputs input { width: 80px; text-align: center; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.readonly-note { font-size: 12px; color: var(--muted); }
.calc-out { font-size: 28px; font-weight: 700; margin: 6px 0; }
.calc-steps { font-size: 13px; color: var(--muted); }
.calc-steps div { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.timeline .change { font-weight: 600; }
.timeline .old { color: var(--bad); text-decoration: line-through; font-weight: 400; }
.timeline .new { color: var(--good); }
.remark { padding: 10px 0; border-bottom: 1px solid var(--line); white-space: pre-wrap; }
.bill-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); gap: 10px; }

/* Modal */
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 520px; max-width: calc(100vw - 32px); max-height: 90vh; overflow-y: auto; background: var(--panel); border-radius: 14px; padding: 22px; z-index: 50; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal .field { margin-bottom: 12px; }
.preview { display: flex; gap: 12px; align-items: center; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; margin-bottom: 12px; }
.preview img { width: 56px; height: 56px; object-fit: contain; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2330; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.err { background: var(--bad); }

@media (max-width: 760px) {
  main { padding: 12px; }
  .topbar { padding: 10px 12px; flex-wrap: wrap; }
  .topbar nav { margin-left: 0; order: 3; width: 100%; }
  .who .name { display: none; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .drawer-body { padding: 12px; }
}
