/* =============================================================================
   Kash Invoices — Stage 3 mobile-first styles
   Owner-facing UI. Tenant branding is applied inline on the invoice header only.
   ========================================================================== */

:root {
  /* Kash Finances brand (owner-facing chrome + CTA) */
  --navy: #003366;
  --blue: #00509E;
  --green: #2ECC71;
  --green-press: #27ae60;

  --ink: #1b2733;
  --ink-soft: #5b6b7b;
  --line: #e4e9ef;
  --bg: #f4f6f9;
  --card: #ffffff;

  /* status colors */
  --draft: #8a94a6;
  --sent: #00509E;
  --paid: #2ECC71;
  --overdue: #e74c3c;

  --radius: 14px;
  --tap: 44px;                 /* minimum touch target */
  --pad: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;            /* >=16px so iOS does not auto-zoom on input focus */
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* dvh keeps sticky bars correct under Safari's collapsing toolbar (vh fallback). */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button { font-family: inherit; font-size: 16px; cursor: pointer; touch-action: manipulation; }
input, textarea, select { font-family: inherit; font-size: 16px; touch-action: manipulation; }

/* ---- App bar (sticky top) ------------------------------------------------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px var(--pad);
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.appbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.appbar .logo {
  width: 36px; height: 36px; border-radius: 9px; object-fit: cover;
  background: var(--bg); display: grid; place-items: center;
  font-weight: 700; color: var(--navy); flex: 0 0 auto;
}
.appbar .name { font-weight: 700; font-size: 17px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .spacer { flex: 1; }

.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  display: grid; place-items: center;
  border: none; background: transparent; color: var(--navy); border-radius: 10px;
}
.icon-btn:active { background: var(--bg); }

/* ---- Content scroll area -------------------------------------------------- */
.screen { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 24px; }
.section { padding: var(--pad); }
.label { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin: 0 0 6px 2px; text-transform: uppercase; letter-spacing: .03em; }

/* ---- Inputs --------------------------------------------------------------- */
.field {
  width: 100%; min-height: var(--tap);
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--ink);
}
.field:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,80,158,.12); }
.field::placeholder { color: #9aa6b4; }

/* ---- Buttons -------------------------------------------------------------- */
.btn {
  min-height: var(--tap); border: none; border-radius: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 18px;
}
.btn-primary { background: var(--green); color: #06371c; }
.btn-primary:active { background: var(--green-press); }
.btn-secondary { background: var(--card); color: var(--navy); border: 1.5px solid var(--line); }
.btn-ghost { background: transparent; color: var(--navy); }
.btn[disabled] { opacity: .5; }
.btn-full { width: 100%; }

.add-line {
  width: 100%; min-height: 52px; border: 2px dashed #c4ceda; border-radius: 14px;
  background: transparent; color: var(--blue); font-weight: 700; margin-top: 4px;
}
.add-line:active { background: #eef3f9; }

/* ---- Line item row -------------------------------------------------------- */
.line-item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 12px;
  position: relative; overflow: hidden;
}
.line-item .desc-wrap { position: relative; }
.line-item .row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stepper button { width: var(--tap); height: var(--tap); border: none; background: var(--card); color: var(--navy); font-size: 22px; font-weight: 700; }
.stepper button:active { background: var(--bg); }
.stepper .qty { min-width: 42px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.price-wrap { position: relative; flex: 1; }
.price-wrap .dollar { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); }
.price-input { padding-left: 26px; text-align: right; font-variant-numeric: tabular-nums; }
.cat-chip {
  min-height: var(--tap); padding: 0 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--navy); font-weight: 600; font-size: 13px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.line-del { position: absolute; top: 8px; right: 8px; width: 36px; height: 36px; border-radius: 9px; border: none; background: transparent; color: #b6c0cc; }
.line-del:active { color: var(--overdue); background: #fdecea; }

/* preset suggestions dropdown */
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 15; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(20,40,70,.12); overflow: hidden; }
.suggest button { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px;
  min-height: var(--tap); padding: 10px 14px; border: none; background: var(--card); text-align: left; border-bottom: 1px solid var(--line); }
.suggest button:last-child { border-bottom: none; }
.suggest button:active { background: var(--bg); }
.suggest .s-desc { font-weight: 600; }
.suggest .s-meta { color: var(--ink-soft); font-size: 13px; white-space: nowrap; }
.suggest .s-new { color: var(--blue); font-weight: 700; }

/* ---- Sticky tax summary + action bar -------------------------------------- */
.dock { position: sticky; bottom: 0; z-index: 18; }
.tax-summary {
  background: #fbfdff; border-top: 1px solid var(--line);
  padding: 10px var(--pad);
  display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 4px 10px; align-items: baseline;
}
.tax-summary .t { font-size: 12px; color: var(--ink-soft); }
.tax-summary .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.tax-summary .total-t { grid-column: 1 / 3; font-size: 14px; color: var(--ink); font-weight: 700; margin-top: 2px; }
.tax-summary .total-v { grid-column: 3 / 5; text-align: right; font-size: 20px; font-weight: 800; color: var(--navy); }

.actionbar {
  display: flex; gap: 10px; padding: 12px var(--pad);
  padding-bottom: calc(12px + var(--safe-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.actionbar .btn-primary { flex: 1; font-size: 17px; }
.actionbar .btn-secondary { flex: 0 0 auto; min-width: 96px; }

/* ---- Bottom sheet (tax category) ----------------------------------------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(12,24,40,.45);
  opacity: 0; transition: opacity .2s ease; }
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 8px 0 calc(12px + var(--safe-bottom));
  transform: translateY(100%); transition: transform .25s ease;
  max-height: 80dvh; overflow-y: auto; overscroll-behavior: contain;
}
.sheet.open { transform: translateY(0); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: #d7dee7; margin: 8px auto 6px; }
.sheet h3 { margin: 4px var(--pad) 12px; font-size: 16px; }
.sheet .opt {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 56px; padding: 12px var(--pad); border: none; background: var(--card);
  text-align: left; border-top: 1px solid var(--line); }
.sheet .opt:active { background: var(--bg); }
.sheet .opt .o-main { font-weight: 600; }
.sheet .opt .o-sub { color: var(--ink-soft); font-size: 13px; }
.sheet .opt .check { color: var(--green); font-weight: 800; font-size: 18px; visibility: hidden; }
.sheet .opt.selected .check { visibility: visible; }
.sheet .opt.selected { background: #f2fbf6; }

/* ---- Filter chips --------------------------------------------------------- */
.chips { display: flex; gap: 8px; padding: 12px var(--pad); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chip { min-height: 38px; padding: 0 14px; border-radius: 19px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink-soft); font-weight: 600; white-space: nowrap; }
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ---- Invoice list rows ---------------------------------------------------- */
.inv-row { display: flex; align-items: center; gap: 12px; padding: 14px var(--pad);
  background: var(--card); border-bottom: 1px solid var(--line); width: 100%; border-left: none; text-align: left; }
.inv-row:active { background: var(--bg); }
.inv-row .col { min-width: 0; flex: 1; }
.inv-row .num { font-weight: 700; }
.inv-row .client { color: var(--ink-soft); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inv-row .right { text-align: right; flex: 0 0 auto; }
.inv-row .amount { font-weight: 800; font-variant-numeric: tabular-nums; }
.inv-row .date { color: var(--ink-soft); font-size: 12px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; }
.badge.draft { background: var(--draft); }
.badge.sent { background: var(--sent); }
.badge.paid { background: var(--paid); color: #06371c; }
.badge.overdue { background: var(--overdue); }

/* ---- Empty state ---------------------------------------------------------- */
.empty { text-align: center; padding: 48px 24px; }
.empty .art { width: 120px; height: 120px; margin: 0 auto 16px; }
.empty h2 { margin: 0 0 6px; }
.empty p { color: var(--ink-soft); margin: 0 0 22px; }

/* ---- Invoice detail ------------------------------------------------------- */
.detail-card { background: var(--card); margin: var(--pad); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.detail-head { padding: 18px; border-bottom: 1px solid var(--line); }
.detail-head .num { font-size: 22px; font-weight: 800; }
.detail-line { display: flex; justify-content: space-between; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.detail-line .ld { min-width: 0; }
.detail-line .lq { color: var(--ink-soft); font-size: 13px; }
.detail-line .lv { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totrow { display: flex; justify-content: space-between; padding: 6px 18px; }
.totrow.grand { font-size: 20px; font-weight: 800; color: var(--navy); padding-top: 12px; padding-bottom: 16px; }

/* ---- Notes (collapsed) ---------------------------------------------------- */
.notes-toggle { background: transparent; border: none; color: var(--blue); font-weight: 700; padding: 8px 0; min-height: var(--tap); }

/* ---- Inline email capture ------------------------------------------------- */
.inline-capture { background: #fff8e6; border: 1px solid #ffe2a8; border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.inline-capture .ic-msg { font-size: 14px; margin-bottom: 8px; color: #7a5b00; }

/* ---- Toast ---------------------------------------------------------------- */
.toast-root { position: fixed; left: 0; right: 0; bottom: calc(16px + var(--safe-bottom)); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,30,60,.28);
  font-weight: 600; max-width: 92%; transform: translateY(20px); opacity: 0; transition: all .22s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: #1e7a47; }
.toast.error { background: #b5392c; }

/* ---- Misc ----------------------------------------------------------------- */
.muted { color: var(--ink-soft); }
.center { text-align: center; }
.spinner { width: 22px; height: 22px; border: 3px solid rgba(255,255,255,.5); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg,#eef2f6,#f7f9fb,#eef2f6); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ── Login screen ────────────────────────────────────────────────────────── */
.login-shell {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 24px 16px;
}
.login-card {
  background: var(--card); border-radius: 16px; padding: 36px 28px 32px;
  width: 100%; max-width: 380px; box-shadow: 0 4px 24px rgba(0,0,0,.08);
  display: flex; flex-direction: column; gap: 12px;
}
.login-logo {
  display: flex; justify-content: center; margin-bottom: 4px;
}
.login-logo-mark {
  width: 52px; height: 52px; border-radius: 14px;
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 800; letter-spacing: -.5px;
}
.login-title { font-size: 22px; font-weight: 700; color: var(--ink); text-align: center; margin: 0; }
.login-sub   { font-size: 14px; color: var(--ink-soft); text-align: center; margin: 0 0 4px; }
.login-input {
  width: 100%; box-sizing: border-box;
  padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 10px;
  font-size: 16px; color: var(--ink); background: var(--bg); outline: none;
  transition: border-color .15s;
}
.login-input:focus { border-color: var(--blue); background: #fff; }
.login-error { color: #e74c3c; font-size: 13px; margin: 0; text-align: center; }
.login-btn {
  margin-top: 4px; padding: 14px; font-size: 16px; font-weight: 600;
  border-radius: 10px; min-height: var(--tap);
}
