/* ==========================================================================
   Invoice app styles. Irving Lopez brand: near-black + sky blue, Inter.
   Light working surface (readable outdoors), dark top bar.
   Mobile-first; on desktop the same phone-width column is centered.
   ========================================================================== */

:root {
  --sky: #0ea5e9;          /* brand accent (on dark) */
  --sky-light: #38bdf8;
  --blue: #0369a1;         /* accent on light: 5.9:1 on white */
  --blue-hover: #075985;
  --blue-tint: #e0f2fe;
  --bg-dark: #080808;
  --card-dark: #141414;
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #111418;
  --ink-soft: #4a5059;
  --mute: #6b7280;         /* 4.8:1 on white */
  --line: #e3e6ea;
  --danger: #b42318;
  --ok: #157f3c;
  --gold: #f5a623;
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bar-h: 64px;
}

/* One rule for every [hidden], so component display rules can never
   override it (this bug hit the old tool three times). */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
body.is-locked { overflow: hidden; }
input, textarea, select, button { font: inherit; color: inherit; }
/* 16px+ inputs stop iOS Safari from zooming on focus. */
input, textarea, select { font-size: 16px; }
a { color: var(--blue); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
em { font-style: normal; color: var(--mute); font-weight: 400; }

/* --- Brand mark (the "IL" tile) ------------------------------------------- */
.mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 10px;
  background: var(--sky); color: #fff; font-weight: 700; font-size: 17px; letter-spacing: -0.02em;
}
.mark--sm { width: 30px; height: 30px; border-radius: 7px; font-size: 12px; flex: none; }

.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg-dark); }

/* --- Buttons --------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; font-size: 16px; text-decoration: none; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-hover); }
.btn-secondary { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { border-color: #c9ced5; }
.btn-danger { background: var(--card); color: var(--danger); border-color: #f1c7c3; }
.btn-block { width: 100%; }
.btn-link {
  background: none; border: 0; padding: 6px 2px; color: var(--blue); font-weight: 600; font-size: 15px;
  cursor: pointer; text-decoration: none;
}
:focus-visible { outline: 3px solid var(--sky-light); outline-offset: 2px; }

/* --- Segmented control ------------------------------------------------------- */
.seg { display: flex; gap: 4px; padding: 4px; background: #e9edf1; border-radius: 12px; }
.seg__btn {
  flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: none; cursor: pointer;
  font-weight: 600; font-size: 15px; color: var(--ink-soft);
}
.seg__btn.is-active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg--small .seg__btn { min-height: 36px; font-size: 14px; }
.seg--tiny { padding: 3px; border-radius: 9px; }
.seg--tiny .seg__btn { min-height: 34px; min-width: 38px; padding: 0 8px; font-size: 15px; }

/* --- Fields -------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.field input, .field select, .field textarea, textarea, .search {
  width: 100%; min-height: 48px; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink);
}
textarea { resize: vertical; }
.field input:focus, .field select:focus, textarea:focus, .search:focus, .item select:focus, .item input:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-tint);
}
.field__hint { color: var(--mute); font-size: 13px; }
.field--inline { margin: 0; }
.field--inline select { min-height: 40px; padding: 6px 10px; font-weight: 600; }
.field--color input { padding: 4px; height: 48px; width: 80px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* --- Auth screen --------------------------------------------------------------- */
.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  padding-top: calc(24px + var(--safe-top)); background: var(--bg-dark);
}
.auth__card { width: 100%; max-width: 400px; background: var(--card); border-radius: 18px; padding: 24px 20px; }
.auth__brand { display: flex; align-items: center; gap: 12px; }
.auth__name { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.auth__tag { color: var(--ink-soft); margin: 10px 0 18px; }
.auth .seg { margin-bottom: 18px; }
.form-error { color: var(--danger); font-weight: 600; margin: 0 0 12px; }
.lang-switch { display: block; margin: 16px auto 0; background: none; border: 0; color: var(--blue); font-weight: 600; cursor: pointer; padding: 8px; }

/* --- Shell: top bar, main, tab bar ------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  min-height: calc(56px + var(--safe-top)); padding: var(--safe-top) 16px 0;
  background: var(--bg-dark); color: #f2f2f2;
}
.topbar__title { font-size: 18px; font-weight: 700; margin: 0; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__back {
  display: inline-flex; align-items: center; gap: 2px; margin-left: -8px; padding: 8px 6px;
  background: none; border: 0; color: var(--sky-light); font-weight: 600; cursor: pointer;
}
.topbar__back svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.main {
  max-width: 560px; margin: 0 auto; padding: 16px 16px calc(var(--bar-h) + 32px + var(--safe-bottom));
}

.tabbar, .actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding-bottom: var(--safe-bottom); background: rgba(255,255,255,.96);
  border-top: 1px solid var(--line); backdrop-filter: blur(8px);
}
.tabbar { display: flex; justify-content: space-around; }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: var(--bar-h); justify-content: center; text-decoration: none; color: var(--mute); font-size: 12px; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--blue); }
.actionbar { display: flex; gap: 8px; padding: 10px 16px calc(10px + var(--safe-bottom)); }
.actionbar .btn { flex: 1; padding: 0 10px; white-space: nowrap; font-size: 15px; }
@media (max-width: 420px) { .actionbar .btn svg { display: none; } }
.actionbar .btn-primary { flex: 1.4; }

/* --- Cards ------------------------------------------------------------------------ */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card__title { font-size: 17px; font-weight: 700; margin: 0 0 12px; }
.card__row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.card--collapse { padding: 0 16px; }
.card--collapse[open] { padding-bottom: 16px; }
.card__summary { display: flex; align-items: center; gap: 12px; padding: 16px; margin: 0 -16px; cursor: pointer; list-style: none; }
.card__summary::-webkit-details-marker { display: none; }
.card__summary-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.card__summary .card__title { margin: 0; }
.card__peek { color: var(--ink-soft); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card__peek.is-cta { color: var(--blue); font-weight: 600; }
.chev { width: 20px; height: 20px; fill: none; stroke: var(--mute); stroke-width: 2; transition: transform .2s; flex: none; }
details[open] .chev { transform: rotate(180deg); }
.eyebrow { font-size: 13px; color: var(--mute); font-weight: 600; }
.docno { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.docno.is-pending { font-size: 15px; font-weight: 500; color: var(--mute); }

/* --- Docs list ------------------------------------------------------------------- */
.setup-banner {
  background: var(--blue-tint); border: 1px solid #bae6fd; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px;
}
.setup-banner p { margin: 0 0 4px; }
.new-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.search { margin-bottom: 10px; }
.list { list-style: none; margin: 14px 0 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list:empty { display: none; }
.list li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; min-height: 64px;
  background: none; border: 0; text-align: left; text-decoration: none; color: inherit; cursor: pointer;
}
.row:hover { background: #fafbfc; }
.row__main { flex: 1; min-width: 0; }
.row__title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__sub { color: var(--mute); font-size: 14px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row__amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge--draft { background: #eef0f3; color: #4a5059; }
.badge--sent { background: var(--blue-tint); color: var(--blue); }
.badge--paid { background: #dcfce7; color: var(--ok); }
.badge--quote { background: #fef3c7; color: #8a5a00; }
.empty { text-align: center; color: var(--mute); padding: 32px 12px; }

/* --- Line items ---------------------------------------------------------------- */
.item { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 12px; background: #fcfcfd; }
.item__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.item__num { font-weight: 700; font-size: 14px; color: var(--ink-soft); }
.item__remove { background: none; border: 0; padding: 8px; margin: -8px; cursor: pointer; color: var(--mute); }
.item__remove svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.item select, .item input, .item textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff;
}
.item__type.is-empty { color: var(--mute); }
.item__type, .item__input { margin-bottom: 8px; }
.item__nums { display: grid; grid-template-columns: 0.8fr 1.1fr 1.3fr; gap: 8px; }
.item__field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.item__label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.item__field select { padding: 10px 6px; }
.affix-box { position: relative; display: block; }
.affix-box .affix { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--mute); pointer-events: none; }
.affix-box input { padding-left: 24px; }
.item__amount { display: flex; justify-content: space-between; align-items: baseline; margin-top: 10px; color: var(--ink-soft); font-size: 14px; }
.item__amount strong { color: var(--ink); font-size: 16px; font-variant-numeric: tabular-nums; }
.btn-add {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 48px;
  border: 1.5px dashed #b8c2cc; border-radius: var(--radius-sm); background: none; color: var(--blue); font-weight: 600; cursor: pointer;
}
.btn-add svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

/* --- Totals --------------------------------------------------------------------- */
.trow { display: flex; justify-content: space-between; padding: 6px 0; font-variant-numeric: tabular-nums; }
.trow--total { border-top: 2px solid var(--ink); margin-top: 10px; padding-top: 12px; font-size: 19px; font-weight: 700; }
.add-links { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 6px; }
.tline { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "label out" "input input"; gap: 6px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.tline__label { grid-area: label; display: flex; align-items: center; gap: 10px; font-weight: 600; }
.tline__remove { background: none; border: 0; color: var(--danger); font-size: 14px; font-weight: 600; cursor: pointer; padding: 4px; }
.tline__input { grid-area: input; display: flex; align-items: center; gap: 8px; }
.tline__input input { flex: 1; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.tline__input .affix { color: var(--mute); font-weight: 600; }
.tline__out { grid-area: out; align-self: center; font-variant-numeric: tabular-nums; font-weight: 600; }

.ed-more { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0 12px; }
.ed-more .btn { flex: 1 1 auto; }
.status { min-height: 1.4em; margin: 8px 0; font-weight: 600; color: var(--ink-soft); }
.status--error { color: var(--danger); }
.status--ok { color: var(--ok); }

/* --- Business -------------------------------------------------------------------- */
.logo-box { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.logo-box img { max-width: 160px; max-height: 80px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fff; }
.logo-box__btns { display: flex; align-items: center; gap: 10px; }
.account-line { text-align: center; color: var(--mute); font-size: 14px; }

/* --- Preview + sheet ---------------------------------------------------------------- */
.preview { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; background: #1f2328; }
.preview__bar { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + var(--safe-top)) 16px 10px; background: var(--bg-dark); color: #fff; }
.preview__title { margin: 0; font-size: 16px; }
.preview__close { background: none; border: 0; color: #fff; padding: 8px; margin: -8px; cursor: pointer; }
.preview__close svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
/* touch-action lets people pinch-zoom the preview pages. */
.preview__pages { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 12px; touch-action: pan-x pan-y pinch-zoom; }
.preview__page { background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.35); max-width: 100%; height: auto; }
.preview__msg { color: #e5e7eb; margin-top: 40px; }
.preview__msg--error { color: #fca5a5; }
.preview__actions { padding: 10px 16px calc(10px + var(--safe-bottom)); background: var(--bg-dark); }

.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.45); }
.sheet__card { width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--card); border-radius: 18px 18px 0 0; padding: 20px 16px calc(16px + var(--safe-bottom)); }
.sheet__btns { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet__btns .btn { flex: 1 1 auto; }

@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet__card { border-radius: 18px; }
}
