* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e3e6ea;
  --text: #1d2530;
  --muted: #6b7684;
  --blue: #2F4190;
  --blue-soft: #eaedf8;
  --green: #1d7d4f;
  --green-soft: #e3f3ea;
  --red: #b4362e;
  --red-soft: #fbe9e7;
  --amber: #9a6a08;
  --amber-soft: #fdf3dc;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(24,32,46,.07);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

/* ---------- sidebar ---------- */
#sidebar {
  width: 210px;
  background: #1b2438;
  color: #cfd6e4;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.brand {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  padding: 20px 18px 16px;
  letter-spacing: .5px;
}
.brand span { color: #8ea2e8; font-weight: 400; }
#sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
#sidebar nav a {
  color: #cfd6e4;
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 13.5px;
}
#sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
#sidebar nav a.active { background: var(--blue); color: #fff; font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 14px 18px; font-size: 11px; color: #71809c; }

/* ---------- main ---------- */
#main { flex: 1; padding: 26px 32px 60px; max-width: 1180px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 700; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ---------- cards / stats ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat .value.pos { color: var(--green); }
.stat .value.neg { color: var(--red); }
.stat .value.warn { color: var(--amber); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-head { padding: 13px 16px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.card-body { padding: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid #eef0f3; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f7f9fc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; }
.badge.paid { background: var(--green-soft); color: var(--green); }
.badge.open, .badge.sent { background: var(--blue-soft); color: var(--blue); }
.badge.partial { background: var(--amber-soft); color: var(--amber); }
.badge.overdue { background: var(--red-soft); color: var(--red); }
.badge.draft { background: #edeff2; color: var(--muted); }

/* ---------- buttons / forms ---------- */
.btn {
  display: inline-block;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 8px 15px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.12); }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--line); }
.btn.secondary:hover { background: #f4f6f9; filter: none; }
.btn.danger { background: var(--red); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.link { background: none; color: var(--blue); padding: 2px 4px; }
.btn:disabled { opacity: .5; cursor: default; }

label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47,65,144,.25); border-color: var(--blue); }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }
.filters { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.filters label.field { margin-bottom: 0; min-width: 140px; }

/* ---------- modal ---------- */
#modal-root:empty { display: none; }
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(20,26,40,.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: 520px;
  box-shadow: 0 12px 40px rgba(10,16,30,.25);
}
.modal.wide { max-width: 900px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); font-size: 16px; font-weight: 700; display: flex; justify-content: space-between; }
.modal-head .x { cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- invoice editor ---------- */
.items-table input { padding: 6px 8px; font-size: 13px; }
.items-table td { padding: 6px 6px; }
.items-table .rm { color: var(--red); cursor: pointer; font-weight: 700; padding: 0 6px; }
.inv-totals { margin-left: auto; width: 260px; margin-top: 10px; }
.inv-totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.inv-totals .grand { font-weight: 800; font-size: 16px; border-top: 2px solid var(--line); padding-top: 8px; }

/* ---------- chart ---------- */
.chart-wrap { overflow-x: auto; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1b2438; color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .25s;
  z-index: 200;
}
#toast.show { opacity: 1; }
#toast.err { background: var(--red); }

/* ---------- receipt thumb ---------- */
.receipt-link { color: var(--blue); text-decoration: none; font-weight: 600; }

/* ---------- print ---------- */
#print-root { display: none; }
@media print {
  body > #app, #toast, #modal-root { display: none !important; }
  #print-root { display: block; }
  body { background: #fff; }
}
.print-invoice { max-width: 720px; margin: 0 auto; padding: 40px 20px; color: #111; font-size: 13px; }
.print-invoice .pi-head { display: flex; justify-content: space-between; margin-bottom: 36px; }
.print-invoice h1 { font-size: 26px; letter-spacing: 1px; }
.print-invoice .co { font-size: 15px; font-weight: 700; }
.print-invoice .pi-meta { text-align: right; color: #444; }
.print-invoice table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.print-invoice th { border-bottom: 2px solid #222; color: #222; padding: 6px 8px; }
.print-invoice td { padding: 7px 8px; border-bottom: 1px solid #ddd; }
.print-invoice .pi-totals { margin-left: auto; width: 240px; margin-top: 14px; }
.print-invoice .pi-totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.print-invoice .pi-totals .grand { font-weight: 800; font-size: 15px; border-top: 2px solid #222; padding-top: 6px; }
.print-invoice .pi-memo { margin-top: 30px; color: #444; }
