:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1c2330;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #1f2937;
  --accent-ink: #ffffff;
  --brand: #2563eb;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: #0f172a;
  color: #cbd5e1;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-size: 18px; font-weight: 700; color: #fff; margin: 6px 8px 18px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  color: #cbd5e1;
  text-decoration: none;
  font-weight: 500;
}
#nav a:hover { background: #1e293b; color: #fff; }
#nav a.active { background: var(--brand); color: #fff; }
.nav-sep {
  margin: 16px 12px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #64748b;
}

/* Main view */
.view { flex: 1; padding: 26px 30px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-sub { color: var(--muted); margin: -10px 0 18px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-weight: 600; cursor: pointer;
  font-size: 13px; text-decoration: none;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.dark { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f1c4c4; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: 5px 9px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* Cards / panels */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.grid-2 { display: grid; grid-template-columns: minmax(420px, 1fr) minmax(420px, 1fr); gap: 22px; align-items: start; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

/* Forms */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-weight: 600; margin-bottom: 5px; font-size: 12.5px; color: #374151; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; color: var(--ink); background: #fff;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* Tables */
table.list { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.list th { background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #64748b; }
table.list tr:last-child td { border-bottom: none; }
table.list tr:hover td { background: #fafbfc; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Status badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: capitalize; }
.badge.draft { background: #eef2f7; color: #475569; }
.badge.sent { background: #e0edff; color: #1d4ed8; }
.badge.paid { background: #dcfce7; color: #15803d; }

/* Line items editor */
.items { width: 100%; border-collapse: collapse; }
.items th { font-size: 11px; text-transform: uppercase; color: #64748b; text-align: left; padding: 4px 6px; }
.items td { padding: 4px 6px; vertical-align: top; }
.items td.amt { white-space: nowrap; padding-top: 12px; font-weight: 600; }
.items input { padding: 7px 8px; }
.items .c-qty { width: 90px; }
.items .c-rate { width: 120px; }
.items .c-del { width: 36px; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); padding: 40px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); background: #fff; }

/* Field rows for flexible bank fields */
.kv-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.kv-row .k { flex: 0 0 38%; }
.kv-row .v { flex: 1; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 50px 16px; z-index: 50; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
.modal .body { padding: 20px; max-height: 70vh; overflow: auto; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.modal .x { cursor: pointer; border: none; background: none; font-size: 20px; color: var(--muted); }

/* Toast */
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--accent); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 100; font-weight: 600; }
.toast.error { background: var(--danger); }

/* sticky preview column */
.preview-col { position: sticky; top: 20px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
