:root {
  --navy: #0d1b2a;
  --navy-2: #13263b;
  --blue: #0065bd;
  --blue-2: #2f7dc3;
  --blue-soft: #e8f2fb;
  --bg: #f3f6f9;
  --card: #ffffff;
  --text: #17212b;
  --muted: #66758a;
  --border: #dce3ea;
  --green: #087443;
  --green-soft: #e6f5ee;
  --red: #b42318;
  --red-soft: #fdecea;
  --amber: #a15c07;
  --amber-soft: #fff4e5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 238px; background: var(--navy);
  color: #cfdae6; display: flex; flex-direction: column; z-index: 20;
}
.brand { padding: 22px 22px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand .mark { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.brand .mark span.dot { width: 10px; height: 10px; border-radius: 50%; background: #4aa3ec; box-shadow: 0 0 0 4px rgba(74,163,236,.15); }
.brand small { display: block; color: #8798ab; margin-top: 4px; font-size: 12px; }
.nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 3px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px; color: #c5d2df; font-size: 14px; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--blue); color: #fff; }
.nav .ico { width: 18px; height: 18px; flex: 0 0 18px; opacity: .9; }
.nav .sep { margin: 12px 10px 4px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #6f8297; }
.sidebar-foot { margin-top: auto; padding: 16px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #8294a8; }
.main { margin-left: 238px; min-height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 22px 32px 14px; }
.topbar h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.content { padding: 8px 32px 44px; max-width: 1320px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 16px; margin: 0; }
.card-body { padding: 20px; }
.card-body.tight { padding: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.btn {
  appearance: none; border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 9px 14px; border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; line-height: 1.2;
}
.btn:hover { background: #f7f9fb; text-decoration: none; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: #0056a3; }
.btn-danger { color: var(--red); border-color: #f0c8c4; background: #fff; }
.btn-danger:hover { background: var(--red-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #eef2f6; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 7px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge-draft { background: #eef2f6; color: #475467; }
.badge-sent { background: var(--blue-soft); color: #07549b; }
.badge-paid, .badge-accepted { background: var(--green-soft); color: var(--green); }
.badge-cancelled, .badge-rejected { background: var(--red-soft); color: var(--red); }
.badge-overdue { background: var(--amber-soft); color: var(--amber); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 12px 16px; border-bottom: 1px solid var(--border); background: #fbfcfd; }
.table td { padding: 13px 16px; border-bottom: 1px solid #eef2f6; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fbfdff; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table a { font-weight: 600; }
.empty { padding: 42px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }
.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat .value { font-size: 26px; font-weight: 750; letter-spacing: -.03em; margin-top: 5px; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters .grow { flex: 1; min-width: 220px; }
.input, select, textarea {
  width: 100%; border: 1px solid var(--border); background: #fff; border-radius: 9px;
  padding: 9px 11px; font-size: 14px; font-family: inherit; color: var(--text);
}
.input:focus, select:focus, textarea:focus { outline: 3px solid rgba(0,101,189,.14); border-color: var(--blue); }
textarea { resize: vertical; min-height: 84px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 650; color: #3b4a5c; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; }
.span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; } .span-9 { grid-column: span 9; } .span-12 { grid-column: span 12; }
.section-title { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 750; margin: 2px 0 12px; }
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.items-table td { padding: 6px 4px; vertical-align: top; }
.items-table input, .items-table select { padding: 8px 9px; font-size: 13.5px; }
.items-table .c-key { width: 20%; } .items-table .c-desc { width: 30%; }
.items-table .c-qty { width: 9%; } .items-table .c-price { width: 14%; }
.items-table .c-tax { width: 10%; } .items-table .c-sum { width: 12%; text-align: right; white-space: nowrap; padding-top: 15px; font-variant-numeric: tabular-nums; }
.items-table .c-del { width: 5%; text-align: right; }
.items-table .remove { border: 0; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; padding: 5px 4px; }
.items-table .remove:hover { color: var(--red); }
.item-extra { font-size: 11.5px; color: var(--red); margin-top: 4px; }
.totals-box { margin-left: auto; width: min(360px, 100%); }
.totals-box .line { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; }
.totals-box .line.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; font-size: 18px; font-weight: 750; }
.totals-box .line .v { font-variant-numeric: tabular-nums; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(6px); border-radius: 0 0 var(--radius) var(--radius); }
.flash { padding: 11px 14px; border-radius: 9px; margin-bottom: 14px; font-size: 14px; }
.flash-ok { background: var(--green-soft); color: #075c38; border: 1px solid #bfe6d2; }
.flash-error { background: var(--red-soft); color: #8f1d14; border: 1px solid #f3c7c1; }
.flash-info { background: var(--blue-soft); color: #0a4e8c; border: 1px solid #c7e0f5; }
.detail-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.detail-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.detail-title h1 { margin: 0; font-size: 24px; }
.detail-meta { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px 24px; margin-top: 16px; }
.detail-meta .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.detail-meta .v { margin-top: 2px; }
.timeline { display: flex; flex-direction: column; gap: 10px; font-size: 13px; }
.timeline .t { display: flex; gap: 9px; align-items: flex-start; }
.timeline .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--blue); margin-top: 6px; flex: 0 0 7px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 20px; }
.tabs a { padding: 12px 12px 10px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--blue); border-bottom-color: var(--blue); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.mobile-menu { display: none; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(900px 500px at 20% 10%, #16324f 0, #0d1b2a 55%, #09131e 100%); padding: 24px; }
.login-card { width: 100%; max-width: 410px; background: #fff; border-radius: 16px; padding: 30px; box-shadow: 0 24px 80px rgba(0,0,0,.35); }
.login-card .brandline { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; margin-bottom: 4px; }
.login-card .brandline .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 4px var(--blue-soft); }
.login-card h1 { font-size: 22px; margin: 14px 0 6px; }
.login-card p { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 4px; }
.help { font-size: 12.5px; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1.35fr .65fr; gap: 18px; align-items: start; }
.list-clean { list-style: none; margin: 0; padding: 0; }
.list-clean li { padding: 10px 0; border-bottom: 1px solid #eef2f6; display: flex; justify-content: space-between; gap: 12px; }
.list-clean li:last-child { border-bottom: 0; }
.letterhead-preview { position: relative; width: 100%; max-width: 420px; aspect-ratio: 210 / 297; background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.letterhead-preview img { width: 100%; height: auto; display: block; }
.letterhead-preview .margin-line { position: absolute; left: 0; right: 0; border-top: 1px dashed #b42318; }
.letterhead-preview .margin-line span { position: absolute; right: 5px; top: 2px; font-size: 10px; font-weight: 600; color: #b42318; background: rgba(255,255,255,.9); padding: 0 3px; border-radius: 2px; }
.letterhead-preview .margin-line.bottom { border-top: 0; border-bottom: 1px dashed #b42318; }
.letterhead-preview .margin-line.bottom span { top: auto; bottom: 2px; }
.kpi { display: flex; align-items: baseline; gap: 8px; }
.kpi .big { font-size: 24px; font-weight: 750; letter-spacing: -.02em; }
.progress-note { font-size: 12px; color: var(--muted); }
@media (max-width: 980px) {
  .grid-2, .grid-3, .grid-4, .two-col { grid-template-columns: 1fr; }
  .detail-meta { grid-template-columns: 1fr 1fr; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .mobile-menu { display: inline-flex; }
  .topbar { padding: 16px 18px 10px; }
  .content { padding: 6px 18px 34px; }
  .form-grid > * { grid-column: span 12 !important; }
}
@media (max-width: 620px) {
  .detail-meta { grid-template-columns: 1fr; }
  .items-table .c-key, .items-table .c-desc { width: auto; }
  .items-table th:nth-child(1), .items-table td:nth-child(1) { display: none; }
}
