:root {
  --navy: #0f1d36; --navy-2: #172a4b; --navy-3: #22385f; --nav-text: #b8c4da; --accent: #2f6fed; --accent-2: #e8f0fe;
  --bg: #f4f6fa; --card: #ffffff; --border: #e3e7ef; --text: #1b2433; --muted: #6a7487; --faint: #9aa3b4;
  --ok: #138a52; --ok-bg: #e6f6ee; --warn: #b36b00; --warn-bg: #fff4e0; --danger: #c23434; --danger-bg: #fdecec; --info-bg: #eaf1ff;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .05); --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.45; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; } .neg { color: var(--danger); } .pos { color: var(--ok); }
.hidden { display: none !important; }

/* ---------- layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex-shrink: 0; background: var(--navy); color: var(--nav-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 40; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; }
.brand-logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #3b82f6, #1e40af); display: grid; place-items: center; font-weight: 700; }
.brand b { font-size: 17px; letter-spacing: .2px; } .brand small { display: block; font-size: 11px; color: var(--nav-text); }
.nav-group { padding: 12px 10px 4px; } .nav-group > div { font-size: 11px; letter-spacing: 1.1px; color: #7c8aa5; padding: 0 10px 6px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--nav-text); margin-bottom: 2px; }
.nav a:hover { background: var(--navy-2); color: #fff; text-decoration: none; }
.nav a.active { background: var(--navy-3); color: #fff; box-shadow: inset 3px 0 0 #60a5fa; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-foot { margin-top: auto; padding: 14px 18px; font-size: 11px; color: #7c8aa5; border-top: 1px solid var(--navy-2); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.demo-strip { background: repeating-linear-gradient(45deg, #fff3cd, #fff3cd 12px, #ffeeba 12px, #ffeeba 24px); color: #7a5300; text-align: center; font-weight: 700; font-size: 12px; letter-spacing: .6px; padding: 5px 10px; border-bottom: 1px solid #f1d58a; }
.header { background: #fff; border-bottom: 1px solid var(--border); padding: 12px 24px; display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 30; }
.header .title h1 { font-size: 19px; } .crumbs { font-size: 12px; color: var(--muted); } .crumbs a { color: var(--muted); }
.header .spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.chip.demo { background: #fff3cd; color: #7a5300; border-color: #f1d58a; } .chip.live { background: var(--ok-bg); color: var(--ok); border-color: #bfe6d0; }
.biz { font-weight: 600; color: var(--text); font-size: 13px; }
.icon-btn { position: relative; border: 1px solid var(--border); background: #fff; border-radius: 8px; width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; } .icon-btn .dot { position: absolute; top: -5px; right: -5px; background: var(--danger); color: #fff; border-radius: 999px; font-size: 10px; font-weight: 700; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 4px; }
.user-btn { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 4px 10px 4px 4px; cursor: pointer; font: inherit; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.user-btn small { display: block; color: var(--muted); font-size: 11px; text-align: left; } .user-btn span { text-align: left; font-size: 13px; }
.dropdown { position: absolute; right: 0; top: 44px; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(15, 29, 54, .15); width: 340px; max-height: 420px; overflow: auto; z-index: 60; }
.dropdown .dd-item { display: block; padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--text); font-size: 13px; } .dropdown .dd-item:hover { background: var(--bg); text-decoration: none; }
.dd-wrap { position: relative; }
.menu-toggle { display: none; }
.content { padding: 22px 24px 40px; max-width: 1500px; width: 100%; }

/* ---------- components */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-h .spacer { flex: 1; } .card-b { padding: 16px; } .card-b.flush { padding: 0; }
.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)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 14px 16px; display: block; color: var(--text); } a.kpi:hover { text-decoration: none; border-color: #c7d2e6; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi .v { font-size: 21px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; } .kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.danger .v { color: var(--danger); } .kpi.warn .v { color: var(--warn); } .kpi.ok .v { color: var(--ok); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: #fff; color: var(--text); padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c2cbdc; background: #fafbfd; text-decoration: none; } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; } .btn.primary:hover { background: #255fd3; }
.btn.danger { color: var(--danger); border-color: #f0c4c4; } .btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.sm { padding: 4px 8px; font-size: 12px; } .btn.ghost { border-color: transparent; background: transparent; }
.btn svg { width: 15px; height: 15px; }
.input, select.input, textarea.input { width: 100%; border: 1px solid #d5dbe6; border-radius: 8px; padding: 7px 10px; font: inherit; background: #fff; color: var(--text); min-height: 36px; }
.input:focus { outline: 2px solid #bcd3ff; border-color: var(--accent); } .input.invalid { border-color: var(--danger); background: #fffafa; }
textarea.input { min-height: 70px; resize: vertical; }
.filters .input { width: auto; min-width: 140px; } .filters input[type=search] { min-width: 220px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; } .field label { display: block; font-size: 12px; font-weight: 600; color: #3b4558; margin-bottom: 4px; }
.field .help { font-size: 11px; color: var(--muted); margin-top: 3px; } .req { color: var(--danger); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500 !important; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: #eef1f6; color: #3b4558; }
.b-ok { background: var(--ok-bg); color: var(--ok); } .b-warn { background: var(--warn-bg); color: var(--warn); } .b-danger { background: var(--danger-bg); color: var(--danger); }
.b-info { background: var(--info-bg); color: #2350b8; } .b-purple { background: #f1ebff; color: #6b3fc9; } .b-teal { background: #e3f7f7; color: #11787a; } .b-grey { background: #eef1f6; color: #59647a; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; border: 1px solid; }
.alert.err { background: var(--danger-bg); color: #8f1f1f; border-color: #f3c2c2; } .alert.warn { background: var(--warn-bg); color: #7a4a00; border-color: #f5d69c; }
.alert.ok { background: var(--ok-bg); color: #0d6a3e; border-color: #bfe6d0; } .alert.info { background: var(--info-bg); color: #1f3f86; border-color: #c9d9ff; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; cursor: pointer; }
.tabs a:hover { color: var(--text); text-decoration: none; } .tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; } .dl dt { color: var(--muted); } .dl dd { margin: 0; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; background: #f8f9fc; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.t td { padding: 9px 12px; border-bottom: 1px solid #edf0f5; vertical-align: top; }
table.t tr:last-child td { border-bottom: none; } table.t tbody tr:hover td { background: #fafbfe; }
table.t tfoot td { font-weight: 700; background: #f8f9fc; border-top: 2px solid var(--border); }
table.t td.num, table.t th.num { text-align: right; }
tr.voided td { color: var(--faint); text-decoration: line-through; }
tr.section td { background: #f2f5fa; font-weight: 700; } tr.total td { font-weight: 700; border-top: 1px solid #cfd6e3; } tr.grand td { font-weight: 800; border-top: 2px solid #8d99ae; background: #f8f9fc; }
td.indent { padding-left: 28px !important; }
.table-foot { display: flex; justify-content: space-between; padding: 8px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }

/* ---------- empty / states */
.empty { text-align: center; padding: 36px 20px; color: var(--muted); } .empty h3 { color: var(--text); margin-bottom: 4px; } .empty .btn { margin-top: 12px; }
.error-panel { border: 1px solid #f3c2c2; background: var(--danger-bg); border-radius: var(--radius); padding: 18px; color: #6b1717; }
.error-panel pre { white-space: pre-wrap; font-size: 12px; background: #fff; padding: 10px; border-radius: 6px; max-height: 200px; overflow: auto; }

/* ---------- production board */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: #eef1f7; border-radius: var(--radius); padding: 10px; min-height: 200px; }
.col-h { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 13px; padding: 2px 4px 10px; }
.pcard { background: #fff; border: 1px solid var(--border); border-radius: 9px; padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); font-size: 12.5px; }
.pcard.overdue { border-left: 4px solid var(--danger); } .pcard.urgent { border-top: 3px solid #e85d04; }
.pcard .row { display: flex; justify-content: space-between; gap: 6px; align-items: center; margin-bottom: 4px; }
.progress { height: 6px; background: #e6eaf2; border-radius: 4px; overflow: hidden; margin: 6px 0; } .progress > div { height: 100%; background: var(--accent); }
.pcard .acts { display: flex; gap: 4px; margin-top: 6px; }

/* ---------- charts */
.chart svg { width: 100%; height: auto; display: block; } .chart text { font-size: 11px; fill: #6a7487; font-family: var(--font); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; } .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 8px; align-items: center; font-size: 12.5px; margin-bottom: 7px; }
.hbar .bar { height: 10px; background: #e6eaf2; border-radius: 5px; overflow: hidden; } .hbar .bar > div { height: 100%; background: var(--accent); border-radius: 5px; }

/* ---------- modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 29, 54, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 620px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 920px; } .modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-b { padding: 18px 20px; } .modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: #fafbfd; border-radius: 0 0 12px 12px; }
.line-row { display: grid; grid-template-columns: 130px 1.6fr .8fr .9fr .9fr 34px; gap: 8px; align-items: center; margin-bottom: 8px; }
.toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); font-size: 13px; max-width: 90vw; }
.toast.err { background: var(--danger); }
.diag { position: fixed; right: 16px; bottom: 16px; width: 420px; max-width: calc(100vw - 32px); background: #fff; border: 2px solid var(--danger); border-radius: 10px; z-index: 300; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); font-size: 12px; }
.diag-h { background: var(--danger); color: #fff; padding: 8px 12px; display: flex; justify-content: space-between; font-weight: 700; }
.diag-b { max-height: 240px; overflow: auto; padding: 8px 12px; } .diag-b pre { white-space: pre-wrap; margin: 4px 0 10px; font-size: 11px; color: #555; }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0f1d36 0%, #22385f 100%); padding: 20px; }
.login { width: 100%; max-width: 420px; } .login .card-b { padding: 26px; }
.signup-cta { margin-top: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 10px; display: flex; flex-direction: column; gap: 2px; }
.login table { font-size: 12px; }

/* ---------- printable documents */
.doc { font-size: 13px; color: #111; } .doc h2 { font-size: 20px; } .doc .doc-h { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #111; padding-bottom: 12px; margin-bottom: 14px; }
.doc table { width: 100%; border-collapse: collapse; margin: 10px 0; } .doc th, .doc td { border-bottom: 1px solid #ddd; padding: 6px 8px; text-align: left; } .doc .num { text-align: right; }
.doc .stamp { display: inline-block; border: 2px solid; padding: 2px 10px; font-weight: 800; letter-spacing: 1px; transform: rotate(-3deg); }
.print-only { display: none; }

@media print {
  body { background: #fff; font-size: 12px; }
  .sidebar, .header, .toolbar, .no-print, .tabs, .demo-strip-screen, .diag, .toast-root, .btn { display: none !important; }
  .content { padding: 0; max-width: none; } .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .print-only { display: block; }
  body.print-doc .app, body.print-doc .login-wrap { display: none !important; }
  body.print-doc .modal-backdrop { position: static; background: none; padding: 0; } body.print-doc .modal { box-shadow: none; max-width: none; }
  body.print-doc .modal-h, body.print-doc .modal-f { display: none; }
  a { color: #000; }
}

/* ---------- responsive */
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 35; }
  .menu-toggle { display: grid; } .header { padding: 10px 14px; gap: 8px; flex-wrap: wrap; } .header .biz, .header .hide-sm { display: none; }
  .content { padding: 16px 14px 30px; } .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); } .dl { grid-template-columns: 120px 1fr; }
  .line-row { grid-template-columns: 1fr 1fr; } .filters .input, .filters input[type=search] { min-width: 0; flex: 1 1 140px; }
  .dropdown { position: fixed; left: 10px; right: 10px; width: auto; top: 60px; }
  .user-btn span { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } .kpi { padding: 12px; } .kpi .v { font-size: 16px; } .kpi .l { font-size: 10.5px; }
  .board { grid-auto-columns: minmax(230px, 85vw); }
}
