:root {
  --lime: #1b4f9c;
  --lime-2: #163f7c;
  --blue: #1b4f9c;
  --sidebar: #16325c;
  --sidebar-2: #0f2342;
  --gold: #e30613;
  --gold-2: #b80510;
  --ink: #1a1f2c;
  --ink-2: #3d4663;
  --muted: #6b7289;
  --line: #e6e8ee;
  --bg: #f3f5f8;
  --card: #ffffff;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(15, 23, 42, .06);
  --shadow-md: 0 14px 34px rgba(22, 50, 92, .12);
  --sidebar-w: 268px;
  --font: Manrope, Inter, ui-sans-serif, system-ui, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --invoice: #6f42c1;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; display: block; }
h1,h2,h3 { margin: 0 0 .4em; letter-spacing: -.02em; font-weight: 800; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: 14px; cursor: pointer; background: #fff; color: var(--ink);
  transition: background .15s ease, box-shadow .15s ease, transform .05s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--lime); color: #fff; box-shadow: 0 6px 16px rgba(11,58,111,.28); }
.btn-primary:hover { background: var(--lime-2); }
.btn-navy { background: var(--sidebar); color: #fff; }
.btn-blue { background: var(--blue); color: #fff; }
.btn-gold { background: var(--gold); color: #fff; }
.btn-gold:hover { background: var(--gold-2); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { height: 34px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

.badge {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: #eef2f6; color: #475569; text-transform: capitalize;
}
.badge.draft { background: #f1f5f9; color: #475569; }
.badge.sent { background: #eff6ff; color: #1d4ed8; }
.badge.confirmed { background: #ecfdf5; color: #047857; }
.badge.shipped { background: #eff6ff; color: #1d4ed8; }
.badge.delivered { background: #f0fdf4; color: #15803d; }
.badge.cancelled { background: #fef2f2; color: #b91c1c; }
.badge.accepted { background: #ecfdf5; color: #047857; }
.badge.declined, .badge.expired, .badge.archived { background: #fef2f2; color: #b91c1c; }
.badge.converted { background: #f5f3ff; color: #6d28d9; }
.badge.customer, .badge.active { background: #ecfdf5; color: #047857; }
.badge.prospect { background: #fffbeb; color: #b45309; }

.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  border-right: 1px solid rgba(255,255,255,.06);
}
.brand {
  display: flex; align-items: center; gap: 12px; padding: 20px 18px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand img { width: 118px; height: auto; object-fit: contain; background: #fff; border-radius: 10px; padding: 8px 10px; }
.brand span { font-weight: 800; letter-spacing: -.02em; font-size: 15px; display: flex; flex-direction: column; line-height: 1.15; }
.brand span em { font-style: normal; font-weight: 600; font-size: 11px; color: #c5d4e8; letter-spacing: .04em; text-transform: uppercase; }
.side-nav { padding: 16px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 10px; color: #b9c6d9; padding: 10px 12px; border-radius: 10px;
  font-size: 14px; font-weight: 500; border-left: 3px solid transparent; transition: background .15s ease, color .15s ease;
}
.side-nav a svg { width: 18px; height: 18px; flex: 0 0 auto; }
.side-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav a.active { background: rgba(255,255,255,.10); color: #fff; border-left-color: var(--gold); font-weight: 700; }
.side-foot { padding: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.side-user { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: #fff; color: var(--sidebar);
  display: grid; place-items: center; font-weight: 800;
}
.side-user strong { display: block; font-size: 13px; }
.side-user span { display: block; font-size: 12px; color: #94a3b8; }
.logout { color: #94a3b8; font-size: 13px; }
.logout:hover { color: #fff; }

.main { min-width: 0; }
.topbar {
  height: 66px; display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
  box-shadow: 0 1px 0 rgba(15,23,42,.02);
}
.top-title { font-weight: 800; font-size: 19px; letter-spacing: -.01em; }
.top-right { margin-left: auto; }
.chip { background: #eef2f7; color: var(--sidebar); padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.icon-btn { border: 0; background: transparent; cursor: pointer; display: none; }
.content { padding: 24px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.pad { padding: 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: #fff; border: 1px solid var(--line); border-top: 3px solid var(--sidebar); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); transition: box-shadow .15s ease, transform .15s ease;
}
.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .03em; }
.stat .value { font-size: 27px; font-weight: 800; margin-top: 6px; letter-spacing: -.03em; color: var(--sidebar); }
.stat .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.table-wrap { overflow: auto; border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
table.data th { font-size: 11.5px; color: var(--muted); font-weight: 700; letter-spacing: .04em; background: #f7f9fb; }
table.data tbody tr { transition: background .1s ease; }
table.data tr:hover td { background: #f5f8fc; }
.row-actions { display: flex; gap: 6px; }

.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, select.input:focus, textarea.input:focus {
  outline: none; border-color: var(--sidebar); box-shadow: 0 0 0 3px rgba(3,38,78,.10);
}
textarea.input { min-height: 90px; resize: vertical; }
label.lbl { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
label.lbl.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; }
label.lbl.chk input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--sidebar); margin: 0; }
.tpl-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.tpl-card {
  display: block; cursor: pointer; border: 2px solid var(--line); border-radius: 14px; padding: 12px;
  background: #fff; transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
  position: relative;
}
.tpl-card input[type="radio"] {
  position: absolute; opacity: 0; pointer-events: none;
}
.tpl-card:hover { border-color: #94a3b8; transform: translateY(-1px); }
.tpl-card.is-selected { border-color: var(--sidebar); box-shadow: 0 0 0 3px rgba(3,38,78,.12); }
.tpl-card svg { display: block; border-radius: 8px; overflow: hidden; background: #f8fafc; }
.tpl-label { margin-top: 10px; }
.tpl-label strong { display: block; font-size: 14px; }
.tpl-tag {
  display: inline-block; margin: 4px 0 6px; padding: 2px 8px; border-radius: 999px;
  background: #eef2f7; color: var(--sidebar); font-size: 11px; font-weight: 700;
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.span-2 { grid-column: span 2; }
.field-error { color: var(--danger); font-size: 12px; margin-top: 4px; }

.empty {
  padding: 56px 20px; text-align: center; color: var(--muted);
}
.empty h3 { color: var(--ink); }

.login-body { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.login-art {
  background: linear-gradient(160deg, var(--sidebar) 0%, var(--sidebar-2) 70%, #041226 100%);
  color: #fff; display: flex; flex-direction: column; justify-content: center; padding: 56px;
  position: relative; overflow: hidden;
}
.login-art::after {
  content: ''; position: absolute; right: -120px; top: -120px; width: 360px; height: 360px;
  border-radius: 50%; background: radial-gradient(circle, rgba(227,6,19,.22), transparent 70%);
}
.login-art img { width: min(320px, 78%); height: auto; object-fit: contain; margin-bottom: 32px; background: #fff; border-radius: 12px; padding: 16px 18px; }
.login-art h1 { font-size: 38px; }
.login-art .kicker { font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: #ffb4b8; margin-bottom: 10px; }
.login-points { margin: 24px 0 0; padding: 0; list-style: none; }
.login-points li { position: relative; padding: 6px 0 6px 22px; color: #d7e0ec; font-size: 14px; }
.login-points li::before { content: ''; position: absolute; left: 0; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: #d4b06a; }
.login-form { display: grid; place-items: center; padding: 32px; background: #f7f8fb; }
.login-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 32px; box-shadow: var(--shadow-md); }
.hint { background: #f8fafc; border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; font-size: 12px; color: var(--muted); }

.split { display: grid; grid-template-columns: 1.15fr .85fr; gap: 16px; align-items: start; }
.doc-preview {
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 24px; min-height: 640px;
}
.ci-title { color: var(--invoice); font-size: 22px; font-weight: 800; margin: 0; }
.ci-meta { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; font-size: 13px; margin: 16px 0 18px; }
.ci-meta span { color: #6b7280; font-weight: 600; }
.ci-meta strong { font-weight: 800; }
.ci-boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.ci-box { background: #efe6fb; border-radius: 10px; padding: 12px 14px; min-height: 130px; }
.ci-box h4 { color: var(--invoice); margin: 0 0 8px; font-size: 14px; }
.ci-table { width: 100%; border-collapse: collapse; }
.ci-table th { background: #5b2ca0; color: #fff; text-align: left; padding: 10px 12px; font-size: 12px; }
.ci-table td { padding: 10px 12px; font-size: 13px; border-bottom: 1px solid #f1e9fb; }
.ci-table tr:nth-child(even) td { background: #f7f2fc; }
.ci-foot { display: flex; justify-content: space-between; gap: 16px; margin-top: 16px; align-items: flex-end; }
.ci-total { font-size: 18px; font-weight: 800; }
.preview-logo { width: 148px; height: 42px; object-fit: contain; object-position: right top; background: transparent; padding: 0; margin-left: auto; }
.ci-totals { display: grid; grid-template-columns: 1fr 240px; gap: 8px 16px; align-items: start; margin-top: 18px; }
.ci-words-label { font-size: 12px; font-weight: 800; }
.ci-words-amount { font-size: 12px; font-weight: 800; margin-top: 6px; max-width: 360px; }
.ci-courier { font-size: 13px; display: flex; justify-content: space-between; padding-bottom: 8px; }
.ci-total-box { border-top: 1.5px solid #111; border-bottom: 1.5px solid #111; padding: 8px 2px; margin: 0; display: flex; justify-content: space-between; font-size: 16px; font-weight: 800; }
.ci-sign { display: block; text-align: center; margin-top: 10px; }
.ci-sign .small { text-align: center; }
.ci-sign img { width: 186px; max-width: 100%; height: auto; display: block; margin: 8px auto 6px; }
.ci-sign img.stamp { display: block; }
.items-table input { width: 100%; border: 0; background: transparent; padding: 6px 0; }
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { font-size: 11px; color: var(--muted); text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); font-weight: 700; letter-spacing: .03em; }
.items-table td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }

.toast-wrap { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--sidebar); color: #fff; padding: 12px 14px; border-radius: 10px; min-width: 220px; box-shadow: var(--shadow-md); }
.toast.error { background: #991b1b; }
.toast.ok { background: #065f46; }
.modal-wrap {
  position: fixed; inset: 0; background: rgba(3,38,78,.45);
  display: none; place-items: center; z-index: 70;
}
.modal-wrap.is-open { display: grid; }
.modal { width: min(460px, calc(100% - 32px)); background: #fff; border-radius: 16px; padding: 24px; box-shadow: var(--shadow-md); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(520px, 100%); background: #fff;
  box-shadow: -20px 0 50px rgba(3,38,78,.16); z-index: 60; overflow: auto; padding: 24px;
}
.backdrop { position: fixed; inset: 0; background: rgba(3,38,78,.35); z-index: 50; }

.two-col { display: grid; grid-template-columns: 1.4fr .8fr; gap: 16px; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 8px; }

@media (max-width: 1100px) {
  .stat-grid, .split, .two-col, .form-grid, .ci-boxes, .ci-totals { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); transform: translateX(-105%); z-index: 40; transition: .2s ease; }
  .sidebar.open { transform: none; }
  .icon-btn.menu-btn { display: inline-flex; }
  .login-body { grid-template-columns: 1fr; }
  .login-art { min-height: 240px; padding: 28px; }
  .content { padding: 14px; }
}
