:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #1e8fff;
  --accent-dim: #1570cc;
  --green: #35c07a;
  --amber: #e8a33d;
  --red: #e5544b;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex: 0 0 220px; background: var(--panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.brand { padding: 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 11px; }
.brand img { width: 34px; height: 38px; flex: 0 0 34px; }
.brand .brand-text { min-width: 0; }
.brand h1 { margin: 0; font-size: 15px; letter-spacing: .3px; white-space: nowrap; }
.brand span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.nav { padding: 10px 0; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 18px;
  color: var(--muted); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--panel-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav-foot { padding: 14px 18px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h2 { margin: 0; font-size: 22px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- controls ---------- */
button, .btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500;
}
button:hover, .btn:hover { border-color: #3b4254; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); }
.btn-danger { color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  padding: 8px 10px; border-radius: 8px; font-size: 13px; font-family: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- panels & tables ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.panel h3 { margin: 0 0 14px; font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); font-weight: 600;
}
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: var(--panel-2); }
tr.clickable { cursor: pointer; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card .k { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); }
.card .v { font-size: 24px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.card .n { font-size: 12px; color: var(--muted); margin-top: 2px; }

.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
}
.pill.draft    { background: #2a2f3a; color: var(--muted); }
.pill.sent     { background: #1b3358; color: #7fb0ff; }
.pill.accepted { background: #14402b; color: var(--green); }
.pill.paid     { background: #14402b; color: var(--green); }
.pill.partial  { background: #40320f; color: var(--amber); }
.pill.void     { background: #40191a; color: var(--red); }
.pill.quote    { background: #2a2f3a; color: var(--muted); }
.pill.invoice  { background: #1b3358; color: #7fb0ff; }

.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---------- modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex;
  align-items: flex-start; justify-content: center; padding: 48px 16px; z-index: 100; overflow: auto;
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  width: 100%; max-width: 560px; padding: 22px;
}
.modal.wide { max-width: 860px; }
.modal h3 { margin: 0 0 16px; font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--text); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- document editor ---------- */
.items-table input, .items-table select { padding: 6px 8px; font-size: 13px; }
.items-table td { padding: 6px 6px; }
.items-table .w-qty { width: 72px; }
.items-table .w-money { width: 100px; }
.items-table .w-disc { width: 68px; }
.totals { margin-left: auto; width: 320px; }
.totals .row { display: flex; justify-content: space-between; padding: 6px 0; }
.totals .row.total {
  border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px;
  font-size: 18px; font-weight: 600;
}
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); padding: 1px 6px; border-radius: 4px; }

.toast {
  position: fixed; bottom: 22px; right: 22px; background: var(--panel-2);
  border: 1px solid var(--line); border-left: 3px solid var(--green);
  padding: 12px 18px; border-radius: 8px; z-index: 200; max-width: 380px;
}
.toast.err { border-left-color: var(--red); }

.catalog-pick { max-height: 380px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.catalog-pick td { cursor: pointer; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; }
  .nav { display: flex; overflow-x: auto; padding: 0; }
  .nav a { white-space: nowrap; }
  main { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .totals { width: 100%; }
}

/* ---------- filter chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 10px; margin: -6px 0 16px; }
.filter-dd { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: 12px; color: var(--muted); }
.filter-dd select { width: auto; min-width: 220px; }
.chip {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 500;
}
.chip:hover { color: var(--text); border-color: #3b4254; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-n { opacity: .7; font-size: 11px; margin-left: 2px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 12px; color: var(--muted); }
label.inline input { width: auto; }
