/* ============================================================
   FAKTUUR — Design tokens
   A South African invoicing tool that should feel like a
   well-kept ledger, not a startup dashboard: warm paper,
   deep bottle-green, muted brass. Confident, quiet, precise.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Colour */
  --ink:        #1B1B18;
  --ink-soft:   #4A4A44;
  --paper:      #F7F4EC;
  --paper-raised: #FFFDF8;
  --green:      #0F211C;
  --green-soft: #1B342D;
  --brass:      #B8935A;
  --brass-soft: #E4D3B4;
  --sage:       #5B6B63;
  --sage-line:  #DAD5C6;
  --rust:       #A23B2E;
  --rust-soft:  #F3E1DD;
  --moss:       #4C6B4F;
  --moss-soft:  #E1E9DD;

  /* Type */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Scale (Elements of Typographic Style-ish ratio ~1.25) */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.75rem;
  --text-2xl: 2.5rem;

  /* Layout */
  --sidebar-w: 15.5rem;
  --radius: 3px;
  --border: 1px solid var(--sage-line);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 0.25em;
  line-height: 1.15;
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); font-weight: 500; }

p { max-width: 62ch; }

a { color: var(--green); }
a.plain { color: inherit; text-decoration: none; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

/* ---------------- App shell ---------------- */

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--green);
  color: #EDEAE0;
  display: flex;
  flex-direction: column;
  padding: 1.75rem 1.25rem;
}

.sidebar .brand {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: #fff;
  margin-bottom: 2.5rem;
  letter-spacing: 0.01em;
}

.sidebar .brand span { color: var(--brass); }

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.sidebar nav a {
  color: #C9C6BA;
  text-decoration: none;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  border-left: 2px solid transparent;
}

.sidebar nav a:hover {
  background: var(--green-soft);
  color: #fff;
}

.sidebar nav a.active {
  color: #fff;
  border-left-color: var(--brass);
  background: var(--green-soft);
}

.sidebar .sidebar-foot {
  margin-top: auto;
  font-size: var(--text-xs);
  color: #8B9188;
  border-top: 1px solid var(--green-soft);
  padding-top: 1rem;
}

.main {
  flex: 1;
  padding: 2.5rem 3rem;
  max-width: 68rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar .eyebrow {
  color: var(--sage);
  font-size: var(--text-sm);
  margin-bottom: 0.15rem;
}

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background: var(--green);
  color: #fff;
}
.btn-primary:hover { background: var(--green-soft); }

.btn-brass {
  background: var(--brass);
  color: var(--green);
}
.btn-brass:hover { background: #C7A473; }

.btn-ghost {
  background: transparent;
  border-color: var(--sage-line);
  color: var(--ink);
}
.btn-ghost:hover { border-color: var(--sage); }

.btn-danger {
  background: transparent;
  border-color: var(--rust);
  color: var(--rust);
}
.btn-danger:hover { background: var(--rust-soft); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: var(--text-xs); }

/* ---------------- Panels & cards ---------------- */

.panel {
  background: var(--paper-raised);
  border: var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.panel + .panel { margin-top: 1.25rem; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1px;
  background: var(--sage-line);
  border: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 2rem;
}

.stat {
  background: var(--paper-raised);
  padding: 1.25rem 1.5rem;
}

.stat .label {
  font-size: var(--text-sm);
  color: var(--sage);
  margin-bottom: 0.35rem;
}

.stat .value {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--ink);
}

.stat .value.brass { color: var(--brass); }
.stat .value.rust { color: var(--rust); }

/* ---------------- Forms ---------------- */

.field { margin-bottom: 1.1rem; }

.field label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--ink-soft);
}

.field .hint {
  font-size: var(--text-xs);
  color: var(--sage);
  margin-top: 0.3rem;
}

input[type=text],
input[type=email],
input[type=password],
input[type=number],
input[type=date],
input[type=tel],
textarea,
select {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--text-base);
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--sage-line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink);
}

input:focus, textarea:focus, select:focus {
  border-color: var(--brass);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.25rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: var(--border);
}

.error-box {
  background: var(--rust-soft);
  border: 1px solid var(--rust);
  color: var(--rust);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  margin-bottom: 1.25rem;
}

.success-box {
  background: var(--moss-soft);
  border: 1px solid var(--moss);
  color: var(--moss);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  margin-bottom: 1.25rem;
}

/* ---------------- Tables ---------------- */

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: var(--text-xs);
  color: var(--sage);
  font-weight: 600;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--sage-line);
}

td {
  padding: 0.85rem 0.75rem;
  border-bottom: 1px solid var(--sage-line);
  font-size: var(--text-sm);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tr.row-link { cursor: pointer; }
tr.row-link:hover { background: rgba(184, 147, 90, 0.08); }

.text-right { text-align: right; }
.text-muted { color: var(--sage); }

/* Money and quantity columns should never wrap mid-number */
td.num, th.text-right, .invoice-doc td:nth-child(2),
.invoice-doc td:nth-child(3), .invoice-doc td:nth-child(4) {
  white-space: nowrap;
}
.invoice-doc td:first-child { width: 55%; }

/* ---------------- Badges ---------------- */

.badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
}

.badge-draft   { background: var(--sage-line); color: var(--ink-soft); }
.badge-sent    { background: var(--brass-soft); color: #7A5E2E; }
.badge-paid    { background: var(--moss-soft); color: var(--moss); }
.badge-overdue { background: var(--rust-soft); color: var(--rust); }

/* ---------------- Empty states ---------------- */

.empty-state {
  text-align: center;
  padding: 3.5rem 2rem;
  color: var(--sage);
}

.empty-state h3 { color: var(--ink); margin-bottom: 0.4rem; }

/* ---------------- Auth pages ---------------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green);
  padding: 2rem;
}

.auth-card {
  background: var(--paper-raised);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 26rem;
}

.auth-card .brand {
  font-family: var(--font-display);
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
}
.auth-card .brand span { color: var(--brass); }

.auth-card .tagline {
  color: var(--sage);
  font-size: var(--text-sm);
  margin-bottom: 2rem;
}

.auth-switch {
  text-align: center;
  margin-top: 1.5rem;
  font-size: var(--text-sm);
  color: var(--sage);
}

/* ---------------- Invoice document ---------------- */

.invoice-doc {
  background: var(--paper-raised);
  border: var(--border);
  padding: 3rem;
}

.invoice-doc .doc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid var(--green);
  padding-bottom: 1.5rem;
  margin-bottom: 1.5rem;
}

.invoice-doc .doc-head .from-name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--green);
}

.invoice-doc .doc-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  color: var(--green);
  text-align: right;
}

.invoice-doc .doc-title .num {
  display: block;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--sage);
  margin-top: 0.25rem;
}

.bill-to {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 2rem;
}

.bill-to .label {
  font-size: var(--text-xs);
  text-transform: none;
  color: var(--sage);
  margin-bottom: 0.3rem;
}

.totals-block {
  margin-left: auto;
  width: 16rem;
  margin-top: 1rem;
}

.totals-block .row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  font-size: var(--text-sm);
}

.totals-block .row.total {
  border-top: 2px solid var(--green);
  margin-top: 0.4rem;
  padding-top: 0.75rem;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--green);
}

/* ---------------- Line item builder (JS) ---------------- */

.item-row {
  display: grid;
  grid-template-columns: 1fr 5.5rem 8rem 8rem 2rem;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.6rem;
}

.item-row .line-amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding-right: 0.5rem;
}

.item-row .remove-line {
  background: none;
  border: none;
  color: var(--sage);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.item-row .remove-line:hover { color: var(--rust); }

.item-head {
  display: grid;
  grid-template-columns: 1fr 5.5rem 8rem 8rem 2rem;
  gap: 0.6rem;
  font-size: var(--text-xs);
  color: var(--sage);
  margin-bottom: 0.5rem;
}

/* ---------------- Print (used for "Download PDF" via browser print) ---------------- */

@media print {
  .sidebar, .topbar .actions, .no-print { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; max-width: none; }
  .invoice-doc { border: none; padding: 0; }
  body { background: #fff; }
}

/* ---------------- Responsive ---------------- */

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 1rem 1.25rem; }
  .sidebar .brand { margin-bottom: 0; margin-right: 1.5rem; }
  .sidebar nav { flex-direction: row; overflow-x: auto; }
  .sidebar .sidebar-foot { display: none; }
  .main { padding: 1.5rem; }
  .form-grid { grid-template-columns: 1fr; }
  .bill-to { grid-template-columns: 1fr; }
}
