:root {
  --ink: #1a1a1a;
  --paper: #f8f6f2;
  --navy: #1e3a5f;
  --gold: #b8860b;
  --gold-light: #d4a843;
  --muted: #6b6560;
  --rule: #d6d1ca;
  --green: #2d5a4a;
  --red: #9e3b3b;
  --card: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* Sign-in */
.signin {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--navy);
}
.signin-card {
  background: var(--paper); border-radius: 16px; padding: 40px 28px;
  text-align: center; width: 100%; max-width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.wordmark { font-family: 'Instrument Serif', serif; font-size: 46px; color: var(--navy); line-height: 1; }
.wordmark .v, .topbar-mark .v { color: var(--gold); }
.card-footer { margin-top: 26px; font-size: 11.5px; letter-spacing: 0.5px; color: var(--muted); }
.signin-sub { font-size: 15px; letter-spacing: 2px; text-transform: uppercase; color: var(--gold); margin-top: 4px; }
.signin-note { color: var(--muted); font-size: 14px; margin: 24px 0; }
.gbtn {
  display: inline-flex; align-items: center; gap: 10px; justify-content: center;
  background: var(--navy); color: #fff; border: none; border-radius: 24px;
  padding: 12px 22px; font-family: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
}
.gbtn:disabled { opacity: 0.5; cursor: default; }
.gbtn-g { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: #fff; color: var(--navy); font-weight: 700; font-size: 13px; }
.error-line { color: var(--red); font-size: 13px; margin-top: 14px; min-height: 18px; }

.setup-alt { display: block; margin: 16px auto 0; }

/* Data sheet link */
.sheet-link { display: block; text-align: center; margin-top: 18px; color: var(--navy); font-size: 13px; }

/* App footer */
.app-footer { text-align: center; padding: 26px 18px 10px; color: var(--muted); font-size: 12px; letter-spacing: 0.4px; }

/* Loading overlay */
.loading { position: fixed; inset: 0; background: rgba(248,246,242,0.75); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 40; color: var(--muted); font-size: 14px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--rule); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Top bar + nav (sticky as one unit) */
.app-head { position: sticky; top: 0; z-index: 5; max-width: 640px; margin: 0 auto; }
.topbar {
  background: var(--navy); color: var(--paper);
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
}
.topbar-mark { font-family: 'Instrument Serif', serif; font-size: 26px; }
.topbar-sub { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--gold-light); margin-left: 8px; }
.topbar-actions { display: flex; gap: 16px; align-items: center; }
.link-btn { background: none; border: none; color: var(--gold-light); font-size: 13px; cursor: pointer; font-family: inherit; }

/* Views */
.app { max-width: 640px; margin: 0 auto; padding-bottom: 24px; }
.view { padding: 20px 18px 8px; }
.view h2 { font-family: 'Instrument Serif', serif; font-weight: 400; font-size: 30px; color: var(--navy); margin: 4px 0 18px; }
.view h3 { font-size: 15px; color: var(--muted); margin: 26px 0 10px; text-transform: uppercase; letter-spacing: 1px; }

/* Form */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.form input, .form select, .form textarea {
  font-family: inherit; font-size: 16px; color: var(--ink);
  padding: 12px 14px; border: 1px solid var(--rule); border-radius: 10px;
  background: var(--card); width: 100%;
}
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--gold-light); border-color: var(--gold-light); }

.toggle { display: flex; background: #efe9e0; border-radius: 12px; padding: 4px; gap: 4px; }
.toggle-opt {
  flex: 1; border: none; background: none; padding: 10px; border-radius: 9px;
  font-family: inherit; font-size: 15px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.toggle-opt.active { background: var(--navy); color: var(--paper); }

.hint { font-size: 12.5px; color: var(--muted); margin-top: -6px; }

/* Receipt-first upload + auto-read status */
.receipt-first { background: #efe9e0; border-radius: 12px; padding: 14px; }
.receipt-first input { background: var(--card); }
.extract-status { font-size: 13px; min-height: 16px; color: var(--muted); }
.extract-status.working { color: var(--navy); }
.extract-status.ok { color: var(--green); }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 20px; width: fit-content; }
.badge.yes { background: #e3efe9; color: var(--green); }
.badge.no  { background: #f6e2e2; color: var(--red); }
.badge.check { background: #f6eede; color: var(--gold); }
.badge.na { background: #eceaf0; color: var(--navy); }

.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.primary {
  background: var(--gold); color: #fff; border: none; padding: 14px; border-radius: 10px;
  font-family: inherit; font-size: 16px; font-weight: 600; cursor: pointer; flex: 1;
}
.primary:active { background: var(--gold-light); }
.ghost { background: none; border: 1px solid var(--rule); color: var(--muted); border-radius: 10px; padding: 14px; font-family: inherit; font-size: 15px; cursor: pointer; }
.form-msg { font-size: 13px; min-height: 18px; }
.form-msg.ok { color: var(--green); }
.form-msg.err { color: var(--red); }

/* Search + list */
.search { width: 100%; font-family: inherit; font-size: 15px; padding: 12px 14px; border: 1px solid var(--rule); border-radius: 10px; margin-bottom: 14px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: var(--card); border: 1px solid var(--rule); border-radius: 12px;
  padding: 14px; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
}
.item-main { min-width: 0; }
.item-desc { font-weight: 600; font-size: 15px; }
.item-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.item-tags { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 12px; background: #efe9e0; color: var(--muted); }
.tag.receipt { background: #e3efe9; color: var(--green); cursor: pointer; }
.item-right { text-align: right; white-space: nowrap; }
.item-amount { font-weight: 600; font-size: 15px; }
.item-amount.income { color: var(--green); }
.item-actions { margin-top: 8px; display: flex; gap: 10px; justify-content: flex-end; }
.mini { background: none; border: none; color: var(--navy); font-size: 12.5px; cursor: pointer; font-family: inherit; padding: 0; }
.mini.del { color: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Summary */
.muted-note { font-size: 13px; color: var(--muted); margin: -8px 0 16px; }
.summary-filter { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; margin-bottom: 16px; }
.summary-filter select { font-family: inherit; font-size: 16px; color: var(--ink); padding: 12px 14px; border: 1px solid var(--rule); border-radius: 10px; background: var(--card); width: 100%; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--rule); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.stat.wide { grid-column: 1 / -1; }
.stat.highlight { background: var(--navy); border-color: var(--navy); }
.stat.highlight .stat-label, .stat.highlight .stat-val { color: var(--paper); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-val { font-size: 22px; font-weight: 600; color: var(--navy); }
.breakdown { display: flex; flex-direction: column; gap: 8px; }
.brow { display: flex; justify-content: space-between; font-size: 14px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.brow span:last-child { font-weight: 600; }
.export { margin-top: 22px; }

/* Tab bar (top) */
.tabbar {
  display: flex; background: var(--card); border-bottom: 1px solid var(--rule);
}
.tab { flex: 1; border: none; background: none; padding: 13px 0; font-family: inherit; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; }
.tab.active { color: var(--navy); border-bottom-color: var(--gold); }

/* Settings: company list */
.company-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.company-row { background: var(--card); border: 1px solid var(--rule); border-radius: 10px; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.company-row span { font-size: 15px; }
.add-company { display: flex; gap: 10px; }
.add-company input { flex: 1; font-family: inherit; font-size: 15px; padding: 12px 14px; border: 1px solid var(--rule); border-radius: 10px; }
.add-company .ghost { flex: 0 0 auto; padding: 12px 20px; }

/* Receipt modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 20; }
.modal-inner { max-width: 90vw; max-height: 90vh; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.modal-inner img { max-width: 100%; max-height: 78vh; border-radius: 10px; background: #fff; }
.modal-inner iframe { width: 86vw; height: 78vh; border: none; border-radius: 10px; background: #fff; }
