/* ── Tokens ─────────────────────────────────────────────────── */
:root {
  /* Light mode (default) */
  --bg:           #f4f6fa;
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --border:       #e2e8f0;
  --border-mid:   #cbd5e1;
  --ink:          #0f172a;
  --ink-2:        #475569;
  --ink-3:        #94a3b8;
  --primary:      #0f7bff;
  --primary-dk:   #0068e8;
  --primary-lt:   #e8f0fe;
  --ok:           #16a374;
  --ok-lt:        #dcfce7;
  --warn:         #d97706;
  --warn-lt:      #fef3c7;
  --danger:       #dc2626;
  --danger-lt:    #fee2e2;
  --secondary:    #1e293b;
  --topbar-bg:    rgba(255,255,255,.97);
  --auth-bg:      linear-gradient(145deg, #eef3ff 0%, #f0fdf9 100%);
  --r:            10px;
  --r-lg:         14px;
  --sh-sm:        0 1px 3px rgba(15,23,42,.07);
  --sh:           0 4px 12px rgba(15,23,42,.09);
  --sh-lg:        0 12px 32px rgba(15,23,42,.12);
  --topbar-h:     56px;
  --sidebar-w:    304px;
}

/* ── Dark mode ──────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:           #0d0f18;
  --surface:      #161926;
  --surface-2:    #1c2033;
  --border:       #272c42;
  --border-mid:   #353c58;
  --ink:          #e8edf8;
  --ink-2:        #8893b0;
  --ink-3:        #4d5670;
  --primary:      #4d9fff;
  --primary-dk:   #3d8fee;
  --primary-lt:   #0f1f3d;
  --ok:           #22c98a;
  --ok-lt:        #0a2218;
  --warn:         #f0a828;
  --warn-lt:      #261a06;
  --danger:       #f06060;
  --danger-lt:    #280e0e;
  --secondary:    #cdd5e8;
  --topbar-bg:    rgba(18,21,36,.97);
  --auth-bg:      linear-gradient(145deg, #0a0d1a 0%, #091410 100%);
  --sh-sm:        0 1px 3px rgba(0,0,0,.25);
  --sh:           0 4px 12px rgba(0,0,0,.35);
  --sh-lg:        0 12px 32px rgba(0,0,0,.45);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ─────────────────────────────────────────────── */
h1 { font-size: 1.6rem;  font-weight: 700; letter-spacing: -.025em; }
h2 { font-size: 1.2rem;  font-weight: 700; letter-spacing: -.015em; }
h3 { font-size: .9375rem; font-weight: 600; }
h4 { font-size: .8125rem; font-weight: 600; }

.hidden { display: none !important; }

/* ── Auth ───────────────────────────────────────────────────── */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--auth-bg);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  padding: 2rem;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: .55rem;
  margin-bottom: 1.5rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}

.auth-card h1 { font-size: 1.3rem; margin-bottom: .3rem; }

.auth-sub {
  color: var(--ink-2);
  font-size: .875rem;
  margin-bottom: 1.25rem;
}

.auth-error {
  color: var(--danger);
  font-size: .8125rem;
  min-height: 1.2rem;
  margin-bottom: .5rem;
}

/* Auth tabs */
.auth-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.25rem;
}

.auth-tab {
  padding: .45rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font: inherit;
  font-size: .875rem;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  transition: color 120ms, border-color 120ms;
}

.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.auth-tab:hover:not(.active) { color: var(--ink); }

.auth-panel { }
.auth-panel.hidden { display: none; }

.auth-form {
  display: grid;
  gap: .75rem;
}

.auth-btn-row {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
  text-decoration: none;
}

.brand-name {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.01em;
}

.topbar-nav {
  display: flex;
  gap: .15rem;
}

.nav-tab {
  padding: .375rem .875rem;
  border-radius: 8px;
  border: none;
  background: none;
  font: inherit;
  font-size: .875rem;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 120ms, color 120ms;
}

.nav-tab:hover  { background: var(--bg); color: var(--ink); }
.nav-tab.active { background: var(--primary-lt); color: var(--primary); }

.topbar-end {
  display: flex;
  align-items: center;
  gap: .625rem;
  margin-left: auto;
  flex-shrink: 0;
}

.save-indicator {
  font-size: .75rem;
  color: var(--ink-3);
  min-width: 48px;
  text-align: right;
}

.user-pill {
  font-size: .75rem;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .3rem .75rem;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  padding: .5rem 1rem;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms, box-shadow 120ms, border-color 120ms, transform 80ms;
  text-decoration: none;
}

.btn:hover  { background: var(--bg); box-shadow: var(--sh-sm); }
.btn:active { transform: scale(.98); }

.btn-sm   { padding: .35rem .7rem; font-size: .8125rem; border-radius: 8px; }
.btn-full { width: 100%; }

.btn-primary  { background: var(--primary); border-color: transparent; color: #fff; }
.btn-primary:hover  { background: var(--primary-dk); }

.btn-secondary { background: var(--secondary); border-color: transparent; color: #fff; }
.btn-secondary:hover { background: #334155; }

.btn-success   { background: var(--ok); border-color: transparent; color: #fff; }
.btn-success:hover   { background: #128862; }

.btn-ghost  { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover  { background: var(--bg); color: var(--ink); box-shadow: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font-size: .75rem;
  cursor: pointer;
  transition: background 120ms;
  flex-shrink: 0;
}

.icon-btn:hover { background: var(--bg); }

.remove-btn { border-color: #fca5a5; background: #fff5f5; color: var(--danger); }
.remove-btn:hover { background: #fee2e2; }

/* Focus styles */
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.icon-btn:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,123,255,.18);
}

/* ── Form elements ──────────────────────────────────────────── */
input, select, textarea {
  font: inherit;
  font-size: .875rem;
  width: 100%;
  padding: .46rem .625rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 120ms;
}

input:hover, select:hover, textarea:hover { border-color: var(--border-mid); }
textarea { resize: vertical; }

label {
  display: grid;
  gap: .3rem;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--ink-2);
}

.invoice-form {
  display: grid;
  gap: 1rem;
}

fieldset {
  border: none;
  padding: 0;
}

.form-section {
  padding-top: .875rem;
  border-top: 1px solid var(--border);
}

.form-section-label {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-3);
  margin-bottom: .625rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: .625rem;
}

.full-width { grid-column: 1 / -1; }

/* ── App shell ──────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Tab views ──────────────────────────────────────────────── */
.tab-view { flex: 1; }

.tab-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
  display: grid;
  gap: 1.25rem;
}

.page-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-subtitle {
  color: var(--ink-2);
  font-size: .875rem;
  margin-top: .2rem;
}

/* ── Stats grid ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1rem 1.125rem;
  box-shadow: var(--sh-sm);
  transition: box-shadow 160ms;
}

.stat-card:hover { box-shadow: var(--sh); }

.stat-label {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-3);
  margin-bottom: .35rem;
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--ink);
  line-height: 1.1;
}

.stat-card.stat-danger .stat-value { color: var(--danger); }
.stat-card.stat-warn  .stat-value { color: var(--warn); }
.stat-card.stat-ok    .stat-value { color: var(--ok); }

/* ── Overview grid ──────────────────────────────────────────── */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

/* ── Panel ──────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.panel-body {
  padding: 1rem;
}

.preview-hint {
  font-size: .75rem;
  color: var(--ink-3);
}

/* ── Card list (overview / receipts) ────────────────────────── */
.card-list { display: flex; flex-direction: column; }

.card-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  transition: background 120ms;
}

.card-item:last-child { border-bottom: none; }
.card-item:hover { background: var(--surface-2); }

.card-item-main { flex: 1; min-width: 0; }

.card-item-title {
  font-size: .875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-item-sub {
  font-size: .75rem;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: .1rem;
}

.card-item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .2rem;
  flex-shrink: 0;
}

.card-item-amount {
  font-size: .875rem;
  font-weight: 600;
}

/* ── Empty state ────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--ink-3);
  gap: .5rem;
}

.empty-icon { font-size: 2rem; display: block; }
.empty-state p { font-size: .875rem; }

/* ── Status pills ───────────────────────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: .17rem .55rem;
  font-size: .69rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  flex-shrink: 0;
}

.status-draft   { background: #e8f0fe; color: #2563eb; }
.status-sent    { background: var(--warn-lt);   color: var(--warn); }
.status-paid    { background: var(--ok-lt);     color: #15803d; }
.status-overdue { background: var(--danger-lt); color: var(--danger); }

/* ── Invoice tab layout ─────────────────────────────────────── */
.invoices-layout {
  display: flex;
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
}

.invoice-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: .75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.search-input {
  padding: .42rem .7rem;
  border-radius: 8px;
  font-size: .8125rem;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}

.pill {
  padding: .22rem .65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font: inherit;
  font-size: .75rem;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}

.pill:hover  { background: var(--bg); color: var(--ink); }
.pill.active { background: var(--primary); border-color: transparent; color: #fff; }

.import-pdf-btn {
  width: 100%;
  justify-content: center;
  border: 1px dashed var(--border-mid);
  color: var(--ink-2);
  font-size: .78rem;
  gap: .4rem;
  padding: .35rem .7rem;
  border-radius: 8px;
}
.import-pdf-btn:hover { background: var(--primary-lt); border-color: var(--primary); color: var(--primary); border-style: solid; }

/* PDF import loading overlay */
.pdf-importing {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(15,23,42,.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: #fff;
  font-size: .9375rem;
  font-weight: 500;
}

.pdf-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.invoice-list-pane {
  flex: 1;
  overflow-y: auto;
}

/* Invoice list item */
.invoice-list-item {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 120ms;
  border-left: 3px solid transparent;
  position: relative;
}

.invoice-list-item:hover   { background: var(--primary-lt); }
.invoice-list-item.selected {
  background: var(--primary-lt);
  border-left-color: var(--primary);
}

.ili-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .5rem;
  margin-bottom: .18rem;
}

.ili-number { font-size: .8125rem; font-weight: 600; }
.ili-amount { font-size: .8125rem; font-weight: 600; flex-shrink: 0; }

.ili-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
}

.ili-customer {
  font-size: .73rem;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ili-due {
  font-size: .73rem;
  color: var(--ink-3);
  flex-shrink: 0;
}

.ili-actions {
  display: flex;
  gap: .25rem;
  opacity: 0;
  transition: opacity 140ms;
  margin-top: .45rem;
}

.invoice-list-item:hover  .ili-actions { opacity: 1; }
.invoice-list-item.selected .ili-actions { opacity: 1; }

/* ── Invoice workspace ──────────────────────────────────────── */
.invoice-workspace {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  min-width: 0;
}

.workspace-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: .75rem;
  color: var(--ink-3);
}

.workspace-empty .empty-icon { font-size: 2.5rem; }
.workspace-empty p { font-size: .9rem; }

.workspace-split {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, .9fr);
  gap: 1rem;
  align-items: start;
}

/* Editor internals */
.editor-actions { display: flex; flex-wrap: wrap; gap: .375rem; }

.line-items-section {
  border-top: 1px solid var(--border);
  padding-top: .875rem;
  display: grid;
  gap: .5rem;
}

.line-items-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.line-items-header-row {
  display: grid;
  grid-template-columns: minmax(180px, 2fr) 72px 96px 96px 32px;
  gap: .4rem;
  padding: 0 0 .25rem;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-3);
}

.line-item-row {
  display: grid;
  grid-template-columns: minmax(180px, 2fr) 72px 96px 96px 32px;
  gap: .4rem;
  align-items: center;
}

.line-items { display: grid; gap: .375rem; }

.photo-preview { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .25rem; }
.photo-preview img {
  width: 64px; height: 64px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

/* ── Invoice preview ────────────────────────────────────────── */
.invoice-preview {
  min-height: 400px;
  padding: 1rem;
  font-size: .8125rem;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: .875rem;
}

.preview-header img {
  width: 48px; height: 48px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.preview-meta { margin-bottom: .75rem; display: grid; gap: .2rem; }

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8125rem;
  margin: .5rem 0;
}

.preview-table th,
.preview-table td {
  padding: .35rem .3rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}

.preview-table th { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-3); }

.preview-total {
  margin-top: .625rem;
  display: grid;
  gap: .18rem;
  justify-content: end;
  text-align: right;
  font-size: .8125rem;
}

.preview-grand { font-weight: 700; font-size: .9375rem; }

/* ── Customers tab ──────────────────────────────────────────── */
.customer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: .875rem;
}

.customer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1rem 1.125rem;
  box-shadow: var(--sh-sm);
  transition: box-shadow 160ms;
  display: grid;
  gap: .25rem;
}

.customer-card:hover { box-shadow: var(--sh); }

.customer-card-initials {
  width: 36px; height: 36px;
  border-radius: 999px;
  background: var(--primary-lt);
  color: var(--primary);
  font-weight: 700;
  font-size: .875rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: .4rem;
}

.customer-card-name { font-weight: 600; font-size: .9375rem; }
.customer-card-detail { font-size: .8125rem; color: var(--ink-2); line-height: 1.5; }

/* ── Toast ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
}

.toast {
  padding: .65rem 1rem;
  border-radius: var(--r);
  background: var(--secondary);
  color: #fff;
  font-size: .8125rem;
  font-weight: 500;
  box-shadow: var(--sh-lg);
  max-width: 300px;
  animation: slideUp 200ms ease;
}

.toast-success { background: var(--ok); }
.toast-error   { background: var(--danger); }
.toast-warn    { background: var(--warn); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(15,23,42,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 150ms ease;
}

.modal-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  padding: 1.25rem;
  animation: slideUp 200ms ease;
}

.modal-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: .75rem;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Theme toggle ───────────────────────────────────────────── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .3rem .6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  font: inherit;
  font-size: .75rem;
  font-weight: 500;
  color: var(--ink-2);
  transition: background 160ms, border-color 160ms, color 160ms;
  flex-shrink: 0;
}

.theme-toggle:hover { background: var(--bg); color: var(--ink); border-color: var(--border-mid); }

.theme-toggle-icon { font-size: .9rem; line-height: 1; }

/* ── Dark mode overrides for elements with hardcoded colors ─── */
[data-theme="dark"] .invoice-preview { color: var(--ink); }
[data-theme="dark"] .preview-table th,
[data-theme="dark"] .preview-table td { border-color: var(--border); }
[data-theme="dark"] input[type="color"] { background: var(--surface-2); }
[data-theme="dark"] .sidebar-header { background: var(--surface); }
[data-theme="dark"] .invoice-sidebar { background: var(--surface-2); }
[data-theme="dark"] .modal-card { background: var(--surface); }
[data-theme="dark"] .auth-card { background: var(--surface); }
[data-theme="dark"] .pdf-importing { background: rgba(0,0,0,.65); }

/* ── Print ──────────────────────────────────────────────────── */
@media print {
  .topbar, .invoice-sidebar, #editorPanel, .toast-container { display: none !important; }
  .invoices-layout { display: block; height: auto; }
  .invoice-workspace { padding: 0; overflow: visible; }
  .workspace-split { display: block; }
  #previewPanel { box-shadow: none; border: none; }
  .invoice-preview { padding: 0; }
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1050px) {
  .workspace-split { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .invoices-layout { flex-direction: column; height: auto; overflow: visible; }
  .invoice-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .invoice-list-pane { max-height: 220px; }
  .invoice-workspace { overflow: visible; }
}

@media (max-width: 680px) {
  .brand-name { display: none; }
  .user-pill  { display: none; }
  .topbar-nav .nav-tab { padding: .375rem .6rem; font-size: .8rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row   { grid-template-columns: 1fr; }
  .line-items-header-row,
  .line-item-row {
    grid-template-columns: 1fr 64px 80px 80px 32px;
  }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .editor-actions { gap: .25rem; }
  .line-items-header-row { display: none; }
  .line-item-row { grid-template-columns: 1fr 1fr; }
  .line-item-row [data-field="amount"],
  .line-item-row .remove-btn { grid-column: span 1; }
}

/* ── Settings ── */
.settings-layout {
  padding: 1.5rem 1.5rem 4rem;
  overflow-y: auto;
  height: 100%;
}
.settings-inner {
  max-width: 680px;
  margin: 0 auto;
}
.settings-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.settings-page-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 .25rem;
}
.settings-save-msg {
  font-size: .8rem;
  font-weight: 500;
  margin-bottom: 1rem;
  min-height: 1.2em;
}
.settings-save-msg.ok  { color: var(--success, #22c55e); }
.settings-save-msg.err { color: var(--danger); }

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.settings-section-title {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-2);
  padding: .875rem 1.25rem .5rem;
}
.settings-section-desc {
  font-size: .78rem;
  color: var(--ink-2);
  padding: 0 1.25rem .25rem;
  margin: 0;
}
.settings-danger-section { border-color: rgba(239,68,68,.35); }

.settings-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  align-items: start;
  gap: 1rem;
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--border);
}
.settings-row-noborder { border-top: none; }
.settings-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-2);
  padding-top: .45rem;
  line-height: 1.4;
}
.settings-control { display: flex; flex-direction: column; gap: .25rem; }
.settings-control input,
.settings-control select,
.settings-control textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--surface-2);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: .85rem;
  padding: .45rem .65rem;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
  resize: vertical;
}
.settings-control input:focus,
.settings-control select:focus,
.settings-control textarea:focus { border-color: var(--primary); }
.settings-select { cursor: pointer; }
.settings-input-short { max-width: 140px; }
.settings-2col { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.settings-inline { display: flex; flex-direction: row; align-items: center; gap: .75rem; flex-wrap: wrap; }
.settings-control-stack { gap: .4rem; }
.settings-hint { font-size: .75rem; color: var(--ink-2); margin: 0; line-height: 1.4; }
.settings-unit { font-size: .82rem; color: var(--ink-2); }

/* Logo preview */
.logo-preview-box {
  width: 120px;
  height: 64px;
  border: 1.5px dashed var(--border-mid);
  border-radius: var(--radius);
  background: var(--surface-2);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-3);
  font-size: .75rem;
}

/* Toggle switch */
.toggle-switch { position: relative; display: inline-flex; width: 40px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--border-mid);
  border-radius: 99px;
  cursor: pointer;
  transition: background .2s;
}
.toggle-track::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 3px; left: 3px;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.toggle-switch input:checked + .toggle-track { background: var(--primary); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(18px); }

/* Danger button */
.btn-danger {
  background: var(--danger, #ef4444);
  color: #fff;
  border-color: transparent;
}
.btn-danger:hover { filter: brightness(1.1); }

@media (max-width: 600px) {
  .settings-row { grid-template-columns: 1fr; gap: .35rem; }
  .settings-label { padding-top: 0; }
}

/* ── Membership plan card ── */
.plan-card {
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: .875rem;
}
.plan-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
}
.plan-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: .2rem;
}
.plan-status {
  font-size: .78rem;
  color: var(--ink-2);
}
.plan-badge {
  display: inline-flex;
  align-items: center;
  padding: .25rem .7rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  background: var(--border);
  color: var(--ink-2);
  white-space: nowrap;
  flex-shrink: 0;
}
.plan-badge.badge-trial  { background: #fef3c7; color: #92400e; }
.plan-badge.badge-pro    { background: var(--primary-lt); color: var(--primary); }
.plan-badge.badge-free   { background: var(--border); color: var(--ink-2); }

[data-theme="dark"] .plan-badge.badge-trial { background: #3b2900; color: #fbbf24; }

.plan-features {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.plan-features li {
  font-size: .82rem;
  color: var(--ink-2);
  padding-left: 1.25rem;
  position: relative;
}
.plan-features li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--primary);
  font-weight: 700;
}
.plan-features li.feat-locked::before { content: "✕"; color: var(--ink-3); }

.plan-actions {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-wrap: wrap;
  padding-top: .25rem;
  border-top: 1px solid var(--border);
}

/* ── Status badges (estimates & invoices list) ── */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  background: var(--border);
  color: var(--ink-2);
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-draft    { background: var(--border);    color: var(--ink-2); }
.badge-sent     { background: var(--primary-lt);color: var(--primary); }
.badge-ok       { background: var(--ok-lt);     color: var(--ok); }
.badge-danger   { background: var(--danger-lt); color: var(--danger); }
.badge-info     { background: var(--primary-lt);color: var(--primary); }

/* ── Estimate preview (inv-* classes) ── */
.inv-preview-wrap {
  background: #fff;
  color: #1e293b;
  padding: 2rem;
  font-size: .8125rem;
  line-height: 1.5;
  position: relative;
  min-height: 100%;
}
[data-theme="dark"] .inv-preview-wrap { background: #fff; color: #1e293b; }

.inv-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--accent, #0f7bff);
}
.inv-logo { max-height: 56px; max-width: 140px; object-fit: contain; }
.inv-logo-placeholder { font-weight: 700; font-size: 1rem; color: #1e293b; }
.inv-preview-meta { text-align: right; }
.inv-doc-type { font-size: .65rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #64748b; margin-bottom: .2rem; }
.inv-number { font-size: 1.1rem; font-weight: 700; color: #0f172a; }
.inv-dates { font-size: .75rem; color: #64748b; margin-top: .25rem; display: flex; flex-direction: column; gap: .1rem; }

.inv-preview-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
}
.inv-party-label { font-size: .65rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #94a3b8; margin-bottom: .3rem; }
.inv-from, .inv-to { font-size: .8rem; color: #334155; }

.inv-line-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.inv-line-table th { text-align: left; font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: #94a3b8; padding: .4rem .5rem; border-bottom: 1px solid #e2e8f0; }
.inv-line-table td { padding: .45rem .5rem; border-bottom: 1px solid #f1f5f9; color: #334155; font-size: .8rem; }
.inv-line-table td:not(:first-child) { text-align: right; }
.inv-line-table th:not(:first-child) { text-align: right; }

.inv-totals { display: flex; flex-direction: column; align-items: flex-end; gap: .3rem; margin-bottom: 1.25rem; }
.inv-total-row { display: flex; gap: 2rem; font-size: .82rem; color: #475569; min-width: 200px; justify-content: space-between; }
.inv-grand-total { font-size: 1rem; font-weight: 700; color: #0f172a; padding-top: .35rem; border-top: 1.5px solid #e2e8f0; margin-top: .15rem; }

.inv-notes { padding: .875rem 1rem; background: #f8fafc; border-radius: 8px; margin-bottom: 1rem; }
.inv-notes strong { display: block; font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #94a3b8; margin-bottom: .35rem; }
.inv-notes p { font-size: .8rem; color: #475569; margin: 0; }

.inv-status-stamp {
  position: absolute;
  top: 2.5rem; right: 2rem;
  font-size: .9rem;
  font-weight: 900;
  letter-spacing: .15em;
  text-transform: uppercase;
  opacity: .12;
  pointer-events: none;
  transform: rotate(-20deg);
  border: 3px solid currentColor;
  padding: .25rem .6rem;
  border-radius: 4px;
}
.est-status-draft    { color: #64748b; }
.est-status-sent     { color: #0f7bff; }
.est-status-accepted { color: #16a374; }
.est-status-declined { color: #dc2626; }
.est-status-converted{ color: #7c3aed; }

/* ── More dropdown ── */
.more-menu-wrap { position: relative; }
.more-btn { display: flex; align-items: center; gap: .3rem; }
.more-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 170px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  box-shadow: var(--sh-lg);
  z-index: 300;
  padding: .35rem;
  overflow: hidden;
}
.more-dropdown.open { display: block; }
.more-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  width: 100%;
  padding: .55rem .75rem;
  border: none;
  background: none;
  border-radius: 8px;
  font: inherit;
  font-size: .875rem;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: background 120ms;
}
.more-item:hover { background: var(--bg); }
.more-item.active { background: var(--primary-lt); color: var(--primary); }

/* ── Data table shared ── */
.data-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  overflow: hidden;
  margin-top: .875rem;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .84rem;
}
.data-table th {
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-2);
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.data-table td {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  vertical-align: top;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }
.data-table .col-num  { text-align: right; }
.data-table .col-center { text-align: center; }
.data-table .col-actions { width: 60px; text-align: right; }
.data-table .row-actions { display: flex; gap: .3rem; justify-content: flex-end; opacity: 0; transition: opacity 120ms; }
.data-table tr:hover .row-actions { opacity: 1; }
.data-table .sub-text { font-size: .75rem; color: var(--ink-2); margin-top: .15rem; }
.data-table .total-row td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border); }

/* ── Contacts table avatar ── */
.contact-avatar {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
}
.contact-initials {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary-lt);
  color: var(--primary);
  font-size: .72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Analytics ── */
.analytics-wrap { display: flex; flex-direction: column; gap: .875rem; }
.analytics-view-tabs { display: flex; gap: .4rem; }
.year-tabs {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  justify-content: center;
  padding: .5rem 0 .25rem;
}
.year-tab {
  padding: .3rem .8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: .8125rem;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.year-tab:hover  { background: var(--bg); color: var(--ink); }
.year-tab.active { background: var(--secondary); color: #fff; border-color: transparent; }

/* ── Products form ── */
.product-form-wrap { margin-top: 1rem; }
.product-form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  padding: 1.25rem;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.product-form-card h4 { margin: 0; }

/* ── Taxable checkbox cell ── */
.taxable-check {
  width: 16px; height: 16px;
  accent-color: var(--primary);
  cursor: default;
}

/* ── Modal shared ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 14px);
  box-shadow: var(--sh-lg);
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  animation: modal-in 180ms cubic-bezier(.2,.8,.4,1);
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(.94) translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem .75rem;
}
.modal-header h3 { margin: 0; font-size: 1rem; font-weight: 700; }
.modal-sub {
  padding: 0 1.25rem .75rem;
  font-size: .84rem;
  color: var(--ink-2);
  margin: 0;
}
.modal-footer {
  display: flex;
  gap: .5rem;
  padding: .875rem 1.25rem 1.1rem;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

/* ── Payment method modal ── */
.payment-modal-card { }
.payment-method-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  padding: .25rem 1.25rem .75rem;
}
.payment-method-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  padding: .875rem .5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius, 10px);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: .78rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 120ms, background 120ms, color 120ms;
  text-align: center;
}
.payment-method-btn:hover { background: var(--bg); border-color: var(--border-mid); }
.payment-method-btn.selected {
  border-color: var(--primary);
  background: var(--primary-lt);
  color: var(--primary);
}
.pm-icon { font-size: 1.4rem; line-height: 1; }

/* ── Invoice status select ── */
.status-select-wrap { display: flex; align-items: center; }
.status-select {
  appearance: none;
  -webkit-appearance: none;
  padding: .32rem .9rem .32rem .6rem;
  border-radius: 99px;
  border: 1.5px solid var(--border-mid);
  background: var(--border);
  color: var(--ink-2);
  font: inherit;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='currentColor' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .5rem center;
  padding-right: 1.6rem;
  transition: background .15s, color .15s, border-color .15s;
}
.status-select:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
