:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2733;
  --muted: #6b7787;
  --line: #e3e8ee;
  --brand: #2f6f4f;
  --brand-ink: #ffffff;
  --accent: #2563eb;
  --danger: #c0392b;
  --draft: #8895a5;
  --sent: #2563eb;
  --paid: #2f9e59;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
/* The `hidden` attribute must beat author display rules (e.g. .modal-backdrop's
   display:flex), or the empty modal shows on page load. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 32px;
  padding: 0 24px; height: 58px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--brand); font-size: 22px; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: none; padding: 8px 14px; border-radius: 8px;
  font: inherit; color: var(--muted); cursor: pointer;
}
.tab:hover { background: var(--bg); color: var(--ink); }
.tab.active { background: var(--brand); color: var(--brand-ink); }

/* Layout */
main { max-width: 960px; margin: 28px auto; padding: 0 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; margin: 0; }
.muted { color: var(--muted); }

/* Cards / panels */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat .value.money { color: var(--brand); }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 9px 16px; border-radius: 8px; font: inherit; cursor: pointer;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.subtle { border-color: transparent; color: var(--accent); background: none; }
.btn.danger { color: var(--danger); border-color: transparent; background: none; }
.btn.small { padding: 5px 10px; font-size: 13px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tbody tr:hover { background: #fafbfc; cursor: pointer; }
td.num, th.num { text-align: right; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* Status pills */
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.draft { background: #eef1f4; color: var(--draft); }
.pill.sent  { background: #e8f0fe; color: var(--sent); }
.pill.paid  { background: #e7f6ec; color: var(--paid); }

/* Forms */
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label { font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd7c7; border-color: var(--brand); }
textarea { resize: vertical; min-height: 64px; }

/* Line items editor */
.items th, .items td { padding: 8px 10px; }
.items input { padding: 7px 9px; }
.col-desc { width: 46%; }
.col-qty  { width: 90px; }
.col-price{ width: 130px; }
.col-amt  { width: 120px; text-align: right; }
.col-x    { width: 36px; }

.totals { margin-top: 16px; margin-left: auto; width: 280px; }
.totals .row { display: flex; justify-content: space-between; padding: 6px 0; }
.totals .row.grand { border-top: 2px solid var(--line); margin-top: 6px; padding-top: 12px; font-weight: 700; font-size: 18px; }

.actions { display: flex; gap: 10px; margin-top: 24px; }
.spacer { flex: 1; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 460px; padding: 24px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal h2 { margin: 0 0 18px; font-size: 18px; }

/* Invoice detail */
.invoice-doc { padding: 32px; }
.invoice-doc .head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 28px; }
.invoice-doc .head h1 { margin: 0; font-size: 28px; letter-spacing: .02em; }
.bill-to { color: var(--muted); font-size: 14px; }
.bill-to strong { color: var(--ink); display: block; font-size: 16px; margin-bottom: 2px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow); z-index: 100; font-size: 14px;
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .tabs .tab { padding: 8px 10px; }
}

/* Print: show only the invoice document */
@media print {
  .topbar, .page-head, .actions, #toast { display: none !important; }
  main { margin: 0; }
  .card { border: none; box-shadow: none; }
}
