:root {
  --bg: #f4f6fb;
  --card: #fff;
  --ink: #142033;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #003087;
  --brand2: #0070e0;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 28px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 14px; align-items: center; }
.logo {
  width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand2)); color: #fff; font-weight: 700;
}
h1 { margin: 0; font-size: 20px; }
header p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.badge { font-size: 12px; padding: 4px 10px; border-radius: 99px; background: #e0ecff; color: var(--brand); }
.badge.bad { background: #fee2e2; color: var(--bad); }
main { max-width: 1250px; margin: 0 auto; padding: 22px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; font-size: 24px; margin-top: 4px; }
.stat.warn strong { color: var(--warn); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
h2 { font-size: 15px; margin: 0 0 12px; }
#draftBox { margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--line); }
textarea, input {
  width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: #fbfcfe; color: var(--ink);
}
textarea:focus, input:focus { outline: 2px solid #bfdbfe; border-color: var(--brand2); }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 9px 14px; }
button:disabled { opacity: 0.6; cursor: wait; }
.primary { background: var(--brand2); color: #fff; font-weight: 600; margin-top: 12px; }
.primary:hover { background: var(--brand); }
.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.chips, .toneRow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.chip { background: #eef2ff; color: var(--brand); padding: 5px 11px; font-size: 13px; border-radius: 99px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
label.full { margin-top: 10px; }
.items { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 14px; }
.items th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 4px; }
.items td { padding: 4px; }
.items input, .items select { padding: 6px 8px; }
.items select { font: inherit; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe; }
.items td.amt { text-align: right; white-space: nowrap; }
.rm { background: none; color: var(--bad); padding: 4px 8px; }
.totalRow { text-align: right; margin-top: 12px; font-size: 16px; }
.warning { background: #fffbeb; color: var(--warn); border: 1px solid #fde68a; padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 10px; }
.askRow { display: flex; gap: 8px; }
.askRow .primary { margin-top: 0; }
.answer { background: #f0f7ff; border-left: 3px solid var(--brand2); padding: 10px 14px; border-radius: 6px; margin-top: 12px; font-size: 14px; white-space: pre-wrap; }
.listHead { display: flex; justify-content: space-between; align-items: center; margin-top: 22px; }
.listHead h2 { margin: 0; }
.list { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.inv { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.inv.overdue { border-color: #fdba74; background: #fffaf3; }
.invTop { display: flex; justify-content: space-between; gap: 8px; }
.invTop strong { font-size: 15px; }
.meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.actions button, .actions a { font-size: 13px; padding: 5px 10px; }
.actions a { text-decoration: none; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); }
.pill { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: #e2e8f0; height: fit-content; }
.pill.PAID, .pill.MARKED_AS_PAID { background: #dcfce7; color: var(--ok); }
.pill.SENT, .pill.UNPAID { background: #dbeafe; color: var(--brand); }
.pill.PARTIALLY_PAID { background: #fef3c7; color: var(--warn); }
.pill.OVERDUE { background: #ffedd5; color: var(--warn); }
.pill.CANCELLED { background: #fee2e2; color: var(--bad); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
dialog { border: none; border-radius: 14px; padding: 22px; width: min(520px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(15, 23, 42, .4); }
.dlgActions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dlgActions .primary { margin-top: 0; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; max-width: 90vw; }
.toast.err { background: var(--bad); }
@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
