/* ============================================================
   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.
   ============================================================ */


: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; }
}

/* ============================================================
   FAKTUUR: teal theme (loaded AFTER style.css)
   One palette shared by the landing page and the whole app.
   Re-themes every page through the design tokens, so it also
   covers any page or component added later.
   ============================================================ */

:root {
  --teal:        #007A74;
  --teal-dark:   #00514D;
  --teal-deep:   #00403D;
  --mint:        #EAF4F3;
  --orange:      #F0821E;

  --ink:         #14302E;
  --ink-soft:    #3F5957;
  --paper:       #EEF4F3;
  --paper-raised:#FFFFFF;
  --green:       var(--teal-deep);   /* sidebar, auth backdrop, document rules */
  --green-soft:  var(--teal-dark);
  --brass:       var(--orange);      /* accent: focus ring, active nav marker */
  --brass-soft:  #FCE5CF;
  --sage:        #4B6462;            /* muted text */
  --sage-line:   #CFE0DE;
  --rust:        #A23B2E;
  --rust-soft:   #F8E4E0;
  --moss:        #1E6B4A;
  --moss-soft:   #DDF0E6;

  --font-display: "Segoe UI", "Helvetica Neue", Roboto, Arial, sans-serif;
  --font-body:    "Segoe UI", "Helvetica Neue", Roboto, Arial, sans-serif;
  --radius: 4px;
}

h1, h2, h3, .display { font-weight: 800; letter-spacing: -0.02em; }
h3 { font-weight: 700; }
a { color: var(--teal); }

/* Sidebar: single-colour wordmark, orange marker on the active page */
.sidebar { border-right: 4px solid var(--orange); }
.sidebar .brand, .auth-card .brand { font-weight: 800; letter-spacing: -0.02em; }
.sidebar .brand span, .auth-card .brand span { color: inherit; }
.sidebar nav a { color: #BFDCD9; }
.sidebar .sidebar-foot { color: #8FB6B2; }

/* Buttons: teal everywhere, white text */
.btn { font-weight: 700; }
.btn-primary { background: var(--teal-dark); color: #fff; }
.btn-primary:hover { background: var(--teal-deep); }
.btn-brass { background: var(--teal); color: #fff; }
.btn-brass:hover { background: var(--teal-dark); }
.btn-ghost { border-color: var(--sage-line); color: var(--teal-dark); }
.btn-ghost:hover { border-color: var(--teal); }

/* Forms and focus */
input:focus, textarea:focus, select:focus { border-color: var(--teal); outline: 2px solid rgba(0,122,116,.25); }

/* Numbers and badges */
.stat .value.brass { color: var(--teal-dark); }
.badge-sent { background: var(--mint); color: var(--teal-dark); }
tr.row-link:hover { background: rgba(0, 122, 116, 0.07); }
th { color: var(--ink-soft); }

/* Auth screens: teal backdrop with the same orange rule as the landing page */
.auth-wrap { background: var(--teal); border-bottom: 6px solid var(--orange); }
.auth-card { box-shadow: 0 18px 40px rgba(0, 40, 38, 0.3); }
.auth-card .brand { color: var(--teal); }

/* Invoice document */
.invoice-doc .doc-head { border-bottom-color: var(--ink); }
.invoice-doc .doc-head .from-name,
.invoice-doc .doc-title { color: var(--teal-dark); }
.totals-block .row.total { border-top-color: var(--ink); color: var(--teal-dark); }

@media print {
  .sidebar { border: 0; }
}

/* --- Company logo --- */
.invoice-doc .doc-logo-center { text-align: center; margin-bottom: 1.25rem; }
.invoice-doc .doc-logo-center img { max-width: 15rem; max-height: 5.5rem; width: auto; height: auto; }
.invoice-doc .doc-logo-right { display: block; margin: 0 0 0.6rem auto; max-width: 13rem; max-height: 5rem; width: auto; height: auto; }
.logo-preview { margin: 0.4rem 0 0.6rem; padding: 0.75rem; border: 1px solid var(--sage-line); border-radius: 6px; background: #fff; display: inline-block; }
.logo-preview img { display: block; max-width: 14rem; max-height: 5rem; }
.check-row { display: block; font-weight: 400; margin: 0.25rem 0; }
.check-row input { margin-right: 0.4rem; }
