:root {
  --ink: #0e0e0c;
  --paper: #f5f2eb;
  --paper2: #ede9e0;
  --green: #00c853;
  --green-dark: #007a32;
  --green-pale: #e8f5e9;
  --warn: #e65100;
  --muted: #6b6b60;
  --whatsapp: #25D366;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Instrument Sans', sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 16px;
}
.grain { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0.05; z-index: 0; }
.card {
  position: relative; z-index: 1; background: var(--paper2); border-radius: 20px;
  padding: 48px 40px; width: 100%; max-width: 420px;
  border: 1px solid var(--paper);
}
.logo { font-family: 'Bebas Neue', sans-serif; font-size: 32px; letter-spacing: 1px; color: var(--ink); margin-bottom: 4px; }
.logo span { color: var(--green); }
.tagline { font-family: 'Instrument Serif', serif; font-style: italic; color: var(--muted); font-size: 15px; margin-bottom: 32px; }
h1 { font-family: 'Bebas Neue', sans-serif; font-size: 28px; letter-spacing: 0.5px; margin-bottom: 8px; font-weight: 400; }
.sub { color: var(--muted); font-size: 14px; margin-bottom: 28px; }
p.body { font-size: 15px; line-height: 1.5; margin-bottom: 14px; }
label, legend { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.optional { font-weight: 400; color: var(--muted); }
input[type="email"], input[type="text"], input[type="tel"], textarea {
  width: 100%; min-height: 48px; padding: 13px 16px; border-radius: 10px; border: 1.5px solid var(--muted);
  background: var(--paper); color: var(--ink); font-family: 'Instrument Sans', sans-serif; font-size: 15px;
  margin-bottom: 6px; transition: border-color 0.15s;
}
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 14px; border: 0; }
.hint { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
.field-error, .form-error {
  font-size: 13px; font-weight: 600; color: var(--warn); margin: 6px 0 0;
}
.form-error { margin: 0 0 14px; }
.status {
  font-size: 14px; background: var(--green-pale); color: var(--ink);
  border-radius: 10px; padding: 12px 14px; margin: 0 0 14px;
}
.choices { display: flex; gap: 10px; }
.choice {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; border: 1.5px solid var(--muted); border-radius: 10px;
  background: var(--paper); font-size: 15px; font-weight: 500; cursor: pointer; margin: 0;
}
.choice input { accent-color: var(--green-dark); width: 18px; height: 18px; }
.choice:has(input:checked) { border-color: var(--green-dark); background: var(--green-pale); }
.btn-primary {
  width: 100%; min-height: 48px; padding: 14px; background: var(--green); color: var(--ink); border: none;
  border-radius: 10px; font-family: 'Instrument Sans', sans-serif; font-weight: 600;
  font-size: 15px; cursor: pointer; transition: background 0.15s; margin-bottom: 14px;
}
/* ink on green-dark is ~3.5:1, below AA for 15px text; paper is ~4.9:1 */
.btn-primary:hover { background: var(--green-dark); color: var(--paper); }
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.6; cursor: not-allowed; }
.divider { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: 12px; margin: 20px 0; }
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--muted); }
.divider span { padding: 0 12px; }
.btn-secondary {
  width: 100%; min-height: 48px; padding: 13px; background: var(--paper); color: var(--ink); border: 1.5px solid var(--muted);
  border-radius: 10px; font-family: 'Instrument Sans', sans-serif; font-weight: 500; font-size: 14px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 10px;
}
.code {
  font-family: 'Bebas Neue', sans-serif; font-size: 44px; letter-spacing: 8px; text-align: center;
  background: var(--paper); border-radius: 10px; padding: 12px; margin: 6px 0 14px;
}
/* Visible keyboard focus on every interactive element */
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, h1:focus-visible {
  outline: 3px solid var(--green); outline-offset: 2px;
}
input:focus, textarea:focus { border-color: var(--green); }
.footer-link { text-align: center; font-size: 13px; color: var(--muted); margin-top: 16px; }
.footer-link a, .link-button { color: var(--green-dark); font-weight: 600; text-decoration: none; display: inline-block; min-height: 48px; line-height: 24px; padding: 12px 10px; }
.link-button { background: none; border: 0; font: inherit; font-weight: 600; cursor: pointer; }
.footer-link a:hover, .link-button:hover { text-decoration: underline; }
[hidden] { display: none !important; }
@media (max-width: 480px) {
  .card { padding: 32px 24px; border-radius: 16px; }
  .logo { font-size: 28px; }
  h1 { font-size: 24px; }
}
a.btn-primary { display: block; text-align: center; text-decoration: none; line-height: 20px; }
.hint.spaced { margin-bottom: 14px; }

/* ---- Dashboard (HEA-38): a full app page, not a centred card. Surfaces are paper-2, never white. ---- */
body.app { display: block; padding: 0; }
.shell { position: relative; z-index: 1; display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink); color: var(--paper); padding: 24px 16px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 24px;
}
.sidebar .logo { color: var(--paper); font-size: 26px; margin: 0 0 0 14px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  min-height: 48px; padding: 0 14px; border: 0; border-radius: 10px; background: none; color: var(--paper);
  font-family: 'Instrument Sans', sans-serif; font-size: 15px; font-weight: 500; text-align: left; cursor: pointer;
}
.nav-item:hover { text-decoration: underline; }
.nav-item[aria-current="page"] { background: var(--green); color: var(--ink); font-weight: 600; text-decoration: none; }
.sidebar .link-button { margin-top: auto; color: var(--green); text-align: left; }
.dash { width: 100%; max-width: 1200px; margin: 0 auto; padding: 28px 32px; }
.dash .sub { margin-bottom: 20px; }
.retry { width: auto; padding: 13px 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card, .panel { background: var(--paper2); border-radius: 14px; padding: 18px 20px; }
.panel { margin-bottom: 20px; min-width: 0; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.stat-value { font-family: 'Bebas Neue', sans-serif; font-size: 34px; line-height: 1.15; margin-top: 6px; }
.stat-value.green { color: var(--green-dark); }
.stat-value.warn { color: var(--warn); }
.stat-sub { font-size: 13px; color: var(--muted); }
.panel-title { font-family: 'Bebas Neue', sans-serif; font-size: 22px; font-weight: 400; letter-spacing: 0.3px; margin-bottom: 12px; }
.home-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.chart { display: block; width: 100%; height: 240px; }
.list { list-style: none; }
.list li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--paper); font-size: 14px; line-height: 1.4;
}
.list li:last-child { border-bottom: 0; }
.row-main, .row-side { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-side { align-items: flex-end; flex-shrink: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-meta, .list time { color: var(--muted); font-size: 13px; }
.list time { flex-shrink: 0; }
.amount { font-family: 'Bebas Neue', sans-serif; font-size: 20px; }
.badge { font-size: 12px; font-weight: 600; border-radius: 20px; padding: 2px 10px; border: 1px solid transparent; }
.badge.paid { background: var(--green-pale); color: var(--green-dark); }
.badge.pending, .badge.confirming { background: var(--paper); color: var(--ink); border-color: var(--muted); }
/* ink on warn passes AA at badge size; warn text on paper does not */
.badge.overdue { background: var(--warn); color: var(--ink); }
.badge.draft, .badge.cancelled { color: var(--muted); border: 1px dashed var(--muted); }
.empty { text-align: center; padding: 40px 24px; }
.empty p { color: var(--muted); max-width: 440px; margin: 0 auto; line-height: 1.5; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  min-height: 48px; min-width: 48px; padding: 0 18px; border-radius: 24px; border: 1.5px solid var(--muted);
  background: var(--paper); color: var(--ink); font-family: 'Instrument Sans', sans-serif; font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.table-state { text-align: center; color: var(--muted); padding: 32px 16px; line-height: 1.5; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--muted); padding: 8px 10px; border-bottom: 1.5px solid var(--paper);
}
.table td { padding: 12px 10px; border-bottom: 1px solid var(--paper); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
@media (max-width: 1100px) { .home-grid { grid-template-columns: 1fr; gap: 0; } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; } /* spare height goes to the content, not the top bar */
  .sidebar {
    position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
    justify-content: space-between; gap: 4px 8px; padding: 8px 32px 12px;
  }
  .sidebar .logo { margin: 0; }
  .sidebar .link-button { order: 2; margin: 0; }
  .nav { order: 3; flex-direction: row; width: 100%; }
  .nav-item { flex: 1; text-align: center; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  /* Mobile layout never wider than 430px, the sidebar's contents included */
  .sidebar { padding: 4px max(16px, calc((100% - 430px) / 2)) 12px; }
  .dash { max-width: 430px; padding: 20px 16px; }
  .stat-grid { gap: 10px; }
  .stat-card, .panel { padding: 14px; }
  .stat-value { font-size: 28px; }
  .chart { height: 200px; }
}
/* Phones: each invoice becomes a stacked card, every cell labelled by its column */
@media (max-width: 700px) {
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table, .table tbody, .table tr { display: block; }
  .table tr { padding: 10px 0; border-bottom: 1px solid var(--paper); }
  .table tr:last-child { border-bottom: 0; }
  .table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border: 0; text-align: right; }
  .table td::before {
    content: attr(data-label); color: var(--muted); font-family: 'Instrument Sans', sans-serif; font-size: 13px; text-align: left;
  }
}
