:root {
    --paper: #f5f4ef;
    --paper-raised: #ffffff;
    --paper-sunken: #eeece4;
    --ink: #16241f;
    --ink-soft: #57645d;
    --ink-faint: #8b9590;
    --line: #dcd9cd;
    --line-strong: #c4c0b0;
    --accent: #1f6e52;
    --accent-ink: #ffffff;
    --accent-soft: #e3efe8;
    --gold: #a97a2a;
    --status-draft-bg: #ece9e0; --status-draft-fg: #6b6455;
    --status-sent-bg: #dfe9f6; --status-sent-fg: #2e5c92;
    --status-paid-bg: #dcefe2; --status-paid-fg: #1f7a4c;
    --status-overdue-bg: #f7e0dd; --status-overdue-fg: #a3392b;
    --status-partial-bg: #ede4f7; --status-partial-fg: #6a3fa0;
    --shadow: rgba(22,36,31,0.10);
    --shadow-strong: rgba(22,36,31,0.18);
    --danger: #a3392b;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --paper: #101915;
      --paper-raised: #17221c;
      --paper-sunken: #0c130f;
      --ink: #ecece4;
      --ink-soft: #a9b3ac;
      --ink-faint: #71796f;
      --line: #2a352d;
      --line-strong: #3a463c;
      --accent: #52c78e;
      --accent-ink: #0c1a13;
      --accent-soft: rgba(82,199,142,0.14);
      --gold: #d3a24f;
      --status-draft-bg: #262a24; --status-draft-fg: #b3ac99;
      --status-sent-bg: #1e2d3f; --status-sent-fg: #86b2e6;
      --status-paid-bg: #17322350; --status-paid-fg: #63d99b;
      --status-overdue-bg: #35211d; --status-overdue-fg: #e8988a;
      --status-partial-bg: #2c2338; --status-partial-fg: #c6a3f0;
      --shadow: rgba(0,0,0,0.35);
      --shadow-strong: rgba(0,0,0,0.55);
      --danger: #e8988a;
    }
  }
  :root[data-theme="dark"] {
    --paper: #101915;
    --paper-raised: #17221c;
    --paper-sunken: #0c130f;
    --ink: #ecece4;
    --ink-soft: #a9b3ac;
    --ink-faint: #71796f;
    --line: #2a352d;
    --line-strong: #3a463c;
    --accent: #52c78e;
    --accent-ink: #0c1a13;
    --accent-soft: rgba(82,199,142,0.14);
    --gold: #d3a24f;
    --status-draft-bg: #262a24; --status-draft-fg: #b3ac99;
    --status-sent-bg: #1e2d3f; --status-sent-fg: #86b2e6;
    --status-paid-bg: #17322350; --status-paid-fg: #63d99b;
    --status-overdue-bg: #35211d; --status-overdue-fg: #e8988a;
    --status-partial-bg: #2c2338; --status-partial-fg: #c6a3f0;
    --shadow: rgba(0,0,0,0.35);
    --shadow-strong: rgba(0,0,0,0.55);
    --danger: #e8988a;
  }

  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }
  h1, h2, h3, .display {
    font-family: 'Fraunces', Georgia, serif;
    text-wrap: balance;
    font-weight: 600;
    margin: 0;
  }
  .mono, .num { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }
  a { color: inherit; }
  button { font-family: inherit; font-size: inherit; }
  ::selection { background: var(--accent-soft); }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

  /* Sidebar */
  #sidebar {
    width: 236px;
    flex-shrink: 0;
    background: var(--paper-raised);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    gap: 4px;
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 22px;
  }
  .brand-mark {
    width: 30px; height: 30px; border-radius: 8px;
    background: var(--accent); color: var(--accent-ink);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Fraunces', serif; font-weight: 700; font-size: 16px;
    flex-shrink: 0;
  }
  .brand-name { font-family: 'Fraunces', serif; font-weight: 600; font-size: 17px; }
  .brand-sub { font-size: 11px; color: var(--ink-faint); margin-top: -2px; }

  .nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: 8px;
    color: var(--ink-soft); text-decoration: none;
    cursor: pointer; border: none; background: none;
    width: 100%; text-align: left; font-size: 14px; font-weight: 500;
  }
  .nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
  .nav-item:hover { background: var(--paper-sunken); color: var(--ink); }
  .nav-item.active { background: var(--accent-soft); color: var(--accent); }
  .nav-spacer { flex: 1; }
  .nav-foot { padding: 10px 12px; font-size: 11px; color: var(--ink-faint); border-top: 1px solid var(--line); margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }
  .brand-credit { color: var(--ink-faint); text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }
  .brand-credit:hover { color: var(--accent); }
  .brand-credit:hover span { text-decoration: underline; }
  .brand-credit svg { width: 13px; height: 13px; flex-shrink: 0; }
  .credit-badge {
    margin-left: auto; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px;
    background: var(--accent-soft); color: var(--accent);
  }
  .credit-badge.low { background: var(--status-overdue-bg); color: var(--status-overdue-fg); }

  /* Main */
  #main { flex: 1; min-width: 0; padding: 32px 40px 60px; max-width: 1120px; }
  .page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
  .page-head h1 { font-size: 26px; }
  .page-sub { color: var(--ink-soft); font-size: 13.5px; margin-top: 4px; }

  .btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
    text-decoration: none;
    font-weight: 600; font-size: 13.5px; cursor: pointer;
    transition: background .12s, border-color .12s, opacity .12s;
  }
  .btn svg { width: 15px; height: 15px; }
  .btn-primary { background: var(--accent); color: var(--accent-ink); }
  .btn-primary:hover { opacity: .9; }
  .btn-secondary { background: var(--paper-raised); border-color: var(--line-strong); color: var(--ink); }
  .btn-secondary:hover { background: var(--paper-sunken); }
  .btn-ghost { background: transparent; color: var(--ink-soft); }
  .btn-ghost:hover { background: var(--paper-sunken); color: var(--ink); }
  .btn-danger { background: transparent; color: var(--danger); }
  .btn-danger:hover { background: var(--status-overdue-bg); }
  .btn-accent-outline { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
  .btn-accent-outline:hover { background: var(--accent); color: var(--accent-ink); }
  .btn:disabled { opacity: .5; cursor: not-allowed; }
  .btn-sm { padding: 6px 11px; font-size: 12.5px; }

  /* Stat tiles */
  .stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }
  .stat-tile { background: var(--paper-raised); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
  .stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 600; }
  .stat-value { font-family: 'Fraunces', serif; font-size: 24px; font-weight: 600; margin-top: 6px; }
  .stat-value.accent { color: var(--accent); }
  .stat-value.warn { color: var(--gold); }

  /* Card / table */
  .card { background: var(--paper-raised); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
  table { width: 100%; border-collapse: collapse; }
  th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-faint); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  td { padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
  tr:last-child td { border-bottom: none; }
  tbody tr:hover { background: var(--paper-sunken); }
  tbody tr[data-open-invoice], tbody tr[data-open-client], tbody tr.admin-org-row, tbody tr.tx-row-linked { cursor: pointer; }
  .row-muted { color: var(--ink-soft); font-size: 12.5px; }
  .empty-state { padding: 60px 20px; text-align: center; color: var(--ink-soft); }
  .empty-state svg { width: 40px; height: 40px; color: var(--ink-faint); margin-bottom: 12px; }
  .empty-state h3 { font-size: 17px; margin-bottom: 6px; color: var(--ink); }

  .pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
  .pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
  .pill-draft { background: var(--status-draft-bg); color: var(--status-draft-fg); }
  .pill-sent { background: var(--status-sent-bg); color: var(--status-sent-fg); }
  .pill-paid { background: var(--status-paid-bg); color: var(--status-paid-fg); }
  .pill-overdue { background: var(--status-overdue-bg); color: var(--status-overdue-fg); }
  .pill-partial { background: var(--status-partial-bg); color: var(--status-partial-fg); }

  .toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
  .search-input { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--paper-raised); color: var(--ink); font-size: 13.5px; min-width: 220px; }
  select.search-input { cursor: pointer; }

  /* Forms */
  .field { display: flex; flex-direction: column; gap: 5px; }
  .field label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
  .field input, .field select, .field textarea {
    padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line-strong);
    background: var(--paper-raised); color: var(--ink); font-size: 14px; font-family: inherit; width: 100%;
  }
  .field textarea { resize: vertical; min-height: 64px; }
  .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
  .field-hint { font-size: 11.5px; color: var(--ink-faint); }
  .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .form-section { background: var(--paper-raised); border: 1px solid var(--line); border-radius: 12px; padding: 22px; margin-bottom: 18px; }
  .form-section h3 { font-size: 15px; margin-bottom: 16px; }
  .section-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

  .items-table th, .items-table td { padding: 9px 10px; }
  .items-table input {
    border: none; border-bottom: 1px dashed var(--line-strong); background: transparent;
    padding: 6px 4px; width: 100%; font-size: 14px; color: var(--ink);
    caret-color: var(--accent); border-radius: 4px 4px 0 0; cursor: text;
    transition: background .1s, border-color .1s;
  }
  .items-table input::placeholder { color: var(--ink-faint); }
  .items-table input:hover { background: var(--paper-sunken); border-bottom-color: var(--accent); }
  .items-table input:focus { background: var(--accent-soft); border-bottom: 1px solid var(--accent); outline: none; }
  .items-table .col-qty input, .items-table .col-price input, .items-table .col-amount { text-align: right; }
  .items-table .col-amount { font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; }
  .items-table .col-del { width: 34px; }
  .icon-btn { width: 28px; height: 28px; border-radius: 6px; border: none; background: transparent; color: var(--ink-faint); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
  .icon-btn:hover { background: var(--status-overdue-bg); color: var(--danger); }
  .icon-btn svg { width: 15px; height: 15px; }
  .icon-btn + .icon-btn { margin-left: 4px; }

  .totals-panel { display: flex; justify-content: flex-end; margin-top: 4px; }
  .totals-box { width: 280px; }
  .totals-line { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; color: var(--ink-soft); }
  .totals-line.grand { border-top: 1px solid var(--line-strong); margin-top: 4px; padding-top: 12px; font-size: 18px; font-weight: 700; color: var(--ink); font-family: 'Fraunces', serif; }
  .totals-line .num { font-family: 'IBM Plex Mono', monospace; }

  .logo-upload { display: flex; align-items: center; gap: 14px; }
  .logo-preview { width: 64px; height: 64px; border-radius: 10px; border: 1px dashed var(--line-strong); display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--paper-sunken); flex-shrink: 0; }
  .logo-preview img { width: 100%; height: 100%; object-fit: contain; }

  /* Invoice sheet — deliberately fixed "paper" look independent of app theme */
  .sheet-wrap { display: flex; justify-content: center; }
  .invoice-sheet {
    background: #ffffff; color: #1a1a1a; width: 100%; max-width: 760px;
    padding: 52px 56px; border-radius: 4px; box-shadow: 0 10px 30px var(--shadow-strong);
    font-family: 'IBM Plex Sans', sans-serif;
  }
  .invoice-sheet .sheet-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 40px; gap: 20px; }
  .invoice-sheet .biz-name { font-family: 'Fraunces', serif; font-size: 19px; font-weight: 600; }
  .invoice-sheet .biz-detail { font-size: 12.5px; color: #6b6b63; line-height: 1.6; margin-top: 4px; white-space: pre-line; }
  .invoice-sheet .sheet-logo { max-width: 130px; max-height: 60px; object-fit: contain; margin-bottom: 8px; }
  .invoice-sheet .inv-title { font-family: 'Fraunces', serif; font-size: 30px; font-weight: 700; letter-spacing: .02em; text-align: right; color: #1f6e52; }
  .invoice-sheet .inv-meta { text-align: right; font-size: 12.5px; color: #6b6b63; margin-top: 6px; line-height: 1.7; }
  .invoice-sheet .inv-meta strong { color: #1a1a1a; font-family: 'IBM Plex Mono', monospace; }
  .invoice-sheet .bill-to { display: flex; gap: 40px; margin-bottom: 30px; }
  .invoice-sheet .bill-to .label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: #9a9689; font-weight: 600; margin-bottom: 6px; }
  .invoice-sheet .bill-to .name { font-weight: 600; font-size: 15px; }
  .invoice-sheet .bill-to .detail { font-size: 12.5px; color: #6b6b63; line-height: 1.6; white-space: pre-line; margin-top: 2px; }
  .invoice-sheet table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
  .invoice-sheet th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: #9a9689; font-weight: 600; padding: 0 0 10px; border-bottom: 1.5px solid #1f6e52; }
  .invoice-sheet th.num, .invoice-sheet td.num { text-align: right; }
  .invoice-sheet td { padding: 11px 0; border-bottom: 1px solid #e6e4da; font-size: 13.5px; }
  .invoice-sheet td.num { font-family: 'IBM Plex Mono', monospace; }
  .invoice-sheet .sheet-totals { display: flex; justify-content: flex-end; margin-top: 14px; }
  .invoice-sheet .sheet-totals-box { width: 240px; }
  .invoice-sheet .sheet-totals-line { display: flex; justify-content: space-between; font-size: 13px; padding: 5px 0; color: #6b6b63; }
  .invoice-sheet .sheet-totals-line .num { font-family: 'IBM Plex Mono', monospace; color: #1a1a1a; }
  .invoice-sheet .sheet-totals-line.grand { border-top: 1.5px solid #1f6e52; margin-top: 6px; padding-top: 12px; font-size: 17px; font-weight: 700; color: #1f6e52; font-family: 'Fraunces', serif; }
  .invoice-sheet .sheet-totals-line.grand .num { font-family: 'IBM Plex Mono', monospace; font-weight: 700; }
  .invoice-sheet .sheet-foot { margin-top: 44px; padding-top: 20px; border-top: 1px solid #e6e4da; display: flex; justify-content: space-between; gap: 30px; }
  .invoice-sheet .sheet-foot .label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: #9a9689; font-weight: 600; margin-bottom: 6px; }
  .invoice-sheet .sheet-foot .detail { font-size: 12px; color: #4a4a44; line-height: 1.7; white-space: pre-line; }
  .invoice-sheet .thanks { text-align: center; margin-top: 34px; font-family: 'Fraunces', serif; font-size: 13px; color: #9a9689; font-style: italic; }

  .invoice-actions { display: flex; justify-content: center; gap: 10px; margin: 20px 0 40px; }

  /* Payment / balance summary on the invoice detail page (app chrome, not the printable sheet) */
  .balance-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }

  /* Payments history card */
  .payment-row-method { font-size: 12px; color: var(--ink-soft); text-transform: capitalize; }
  .payment-empty { padding: 34px 20px; text-align: center; color: var(--ink-soft); font-size: 13.5px; }

  /* Receipt sheet — reuses .invoice-sheet as the base "paper" look */
  .invoice-sheet .receipt-badge {
    display: inline-block; margin-top: 10px; padding: 4px 12px; border-radius: 999px;
    font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  }
  .invoice-sheet .receipt-badge.full { background: #dcefe2; color: #1f7a4c; }
  .invoice-sheet .receipt-badge.partial { background: #ede4f7; color: #6a3fa0; }

  /* Toasts */
  #toast-wrap { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 500; }
  .toast { background: var(--ink); color: var(--paper); padding: 11px 16px; border-radius: 8px; font-size: 13.5px; box-shadow: 0 6px 20px var(--shadow-strong); display: flex; align-items: center; gap: 8px; animation: toast-in .18s ease-out; }
  .toast.err { background: var(--danger); color: #fff; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

  /* Support widget — floating help button, right side; raised above the toast stack (also bottom-right) so an incoming toast never covers it */
  #support-widget { position: fixed; right: 20px; bottom: 84px; z-index: 300; }
  .support-fab {
    width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
    background: var(--paper-raised); color: var(--ink-soft); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 20px var(--shadow-strong);
  }
  .support-fab:hover { color: var(--accent); border-color: var(--accent); }
  .support-fab svg { width: 20px; height: 20px; }
  .support-popover {
    position: absolute; bottom: 54px; right: 0; width: 200px;
    background: var(--paper-raised); border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 12px 32px var(--shadow-strong); padding: 10px;
  }
  .support-popover-title { font-size: 12px; font-weight: 600; color: var(--ink-faint); padding: 4px 8px 8px; }
  .support-link {
    display: flex; align-items: center; gap: 9px; padding: 9px 8px; border-radius: 8px;
    color: var(--ink); text-decoration: none; font-size: 13.5px; font-weight: 500;
  }
  .support-link:hover { background: var(--paper-sunken); color: var(--accent); }
  .support-link svg { width: 16px; height: 16px; flex-shrink: 0; }

  .readonly-banner { background: var(--status-overdue-bg); color: var(--status-overdue-fg); padding: 9px 16px; font-size: 13px; text-align: center; font-weight: 500; }

  .low-credit-banner {
    display: flex; align-items: center; gap: 10px;
    background: var(--status-overdue-bg); color: var(--status-overdue-fg);
    border-radius: 10px; padding: 12px 16px; font-size: 13.5px; font-weight: 500;
  }
  .low-credit-banner svg { width: 18px; height: 18px; flex-shrink: 0; }
  .topup-presets { display: flex; flex-wrap: wrap; gap: 8px; }

  .modal-backdrop { position: fixed; inset: 0; background: rgba(10,14,12,.45); display: flex; align-items: center; justify-content: center; z-index: 400; padding: 20px; }
  .modal { background: var(--paper-raised); border-radius: 12px; padding: 26px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px var(--shadow-strong); }
  .modal h3 { font-size: 17px; margin-bottom: 8px; }
  .modal p { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 20px; }
  .modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

  .modal-wizard { max-width: 480px; }
  .wizard-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
  .wizard-progress { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 600; }
  .wizard-body { margin: 16px 0 4px; }
  .note-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
  .note-chip {
    border: 1px solid var(--line-strong); background: var(--paper-sunken); color: var(--ink-soft);
    border-radius: 999px; padding: 5px 11px; font-size: 11.5px; cursor: pointer; text-align: left;
    transition: background .1s, border-color .1s, color .1s;
  }
  .note-chip:hover { border-color: var(--accent); color: var(--ink); }
  .note-chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

  /* Mobile top bar + off-canvas sidebar drawer (hidden on desktop) */
  #topbar { display: none; }
  #sidebar-backdrop { display: none; }

  @media (max-width: 1023px) {
    #shell { flex-direction: column; }
    #topbar {
      display: flex; align-items: center; gap: 12px; padding: 12px 16px;
      background: var(--paper-raised); border-bottom: 1px solid var(--line);
      position: sticky; top: 0; z-index: 120;
    }
    #topbar .icon-btn { width: 34px; height: 34px; color: var(--ink); }
    #topbar .icon-btn svg { width: 19px; height: 19px; }
    .topbar-brand { font-family: 'Fraunces', serif; font-weight: 600; font-size: 15px; }

    #sidebar {
      position: fixed; top: 0; left: 0; bottom: 0; z-index: 200;
      width: 260px; max-width: 82vw;
      transform: translateX(-100%);
      transition: transform .2s ease-out;
      box-shadow: 0 0 0 transparent;
    }
    #sidebar.open { transform: translateX(0); box-shadow: 12px 0 32px var(--shadow-strong); }
    #sidebar-backdrop {
      display: block; position: fixed; inset: 0; background: rgba(10,14,12,.45);
      z-index: 190; opacity: 0; pointer-events: none; transition: opacity .2s ease-out;
    }
    #sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

    #main { padding: 22px 18px 60px; }
    .stat-row { grid-template-columns: repeat(2, 1fr); }
    .balance-row { grid-template-columns: repeat(2, 1fr); }
  }

  @media (max-width: 639px) {
    .form-grid { grid-template-columns: 1fr; }
    .balance-row { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-input { min-width: 0; width: 100%; }
    .page-head { align-items: stretch; }
    .page-head .btn { justify-content: center; }

    .invoice-sheet { padding: 30px 22px; }
    .invoice-sheet .sheet-top { flex-direction: column; }
    .invoice-sheet .inv-title, .invoice-sheet .inv-meta { text-align: left; }

    /* Card-ified tables: only for tables opted in via .table-cards */
    .table-cards table, .table-cards thead, .table-cards tbody, .table-cards th, .table-cards td, .table-cards tr { display: block; }
    .table-cards thead { position: absolute; left: -9999px; top: -9999px; }
    .table-cards tbody tr {
      padding: 12px 14px; border-bottom: 1px solid var(--line);
      display: flex; flex-direction: column; gap: 6px;
    }
    .table-cards tbody tr:last-child { border-bottom: none; }
    .table-cards td {
      border: none; padding: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px;
      font-size: 13.5px;
    }
    .table-cards td::before {
      content: attr(data-label); font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
      color: var(--ink-faint); font-weight: 600; flex-shrink: 0;
    }
    .table-cards td:empty { display: none; }
  }

  @media print {
    body.printing * { visibility: hidden; }
    body.printing .print-target, body.printing .print-target * { visibility: visible; }
    body.printing .print-target { position: absolute; top: 0; left: 0; width: 100%; margin: 0; box-shadow: none; border-radius: 0; }
    @page { size: A4; margin: 14mm; }
  }

/* Login screen */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px 30px;
  box-shadow: 0 20px 50px var(--shadow-strong);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .page-sub { margin-bottom: 22px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; }
.login-error {
  background: var(--status-overdue-bg); color: var(--status-overdue-fg);
  border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 14px;
}
.app-loading { min-height: 100vh; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--ink-faint); font-size: 13.5px; }
.app-loading::before {
  content: ''; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.password-field { position: relative; }
.password-field input { padding-right: 40px; }
.password-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border: none; background: transparent; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink-faint);
}
.password-toggle:hover { background: var(--paper-sunken); color: var(--ink-soft); }
.password-toggle svg { width: 17px; height: 17px; }
.login-switch {
  margin-top: 18px; text-align: center; font-size: 13px; color: var(--ink-faint);
}
.login-switch a { color: var(--accent); font-weight: 600; text-decoration: none; }
.login-switch a:hover { text-decoration: underline; }
.login-footer {
  margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line);
  text-align: center; font-size: 11.5px;
}
.login-footer a { color: var(--ink-faint); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.login-footer a svg { width: 14px; height: 14px; flex-shrink: 0; }
.login-footer a:hover { color: var(--accent); }
.login-footer strong { color: var(--ink-soft); font-weight: 600; }
.login-footer a:hover strong { color: var(--accent); }
