:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f5f7;
  color: #172033;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #dfe4ea;
  --muted: #6b7280;
  --text: #172033;
  --red: #d6202a;
  --red-dark: #b3151d;
  --blue: #2563eb;
  --green: #15803d;
  --amber: #b45309;
  --shadow: 0 16px 44px rgba(15, 23, 42, .07);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: #f4f5f7; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 11px max(20px, calc((100vw - 1400px) / 2));
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, .95);
  backdrop-filter: blur(14px);
}

.brand-lockup { display: flex; align-items: center; gap: 14px; }
.brand-lockup.compact { min-width: 220px; }
.store-mark {
  display: grid; place-items: center; width: 58px; height: 58px; border-radius: 16px;
  background: var(--red); color: white; font-size: 18px; font-weight: 850; letter-spacing: .03em;
}
.store-mark.small { width: 46px; height: 46px; border-radius: 13px; font-size: 14px; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 10px; font-weight: 850; letter-spacing: .14em; }
.brand-lockup strong { font-size: 16px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-name { color: var(--muted); font-size: 13px; font-weight: 650; }

.page-shell { width: min(1400px, calc(100% - 36px)); margin: 0 auto; padding: 38px 0 70px; }
.page-heading { margin-bottom: 26px; }
.page-heading h1 { margin: 0; font-size: clamp(31px, 4vw, 45px); letter-spacing: -.035em; }
.page-heading > p:last-child, .page-heading div > p:last-child { margin: 8px 0 0; color: var(--muted); }
.split-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px;
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 10px; background: white;
  color: var(--text); font-size: 13px; font-weight: 750;
}
.button:hover:not(:disabled) { border-color: #c8d0da; background: #f8fafc; }
.button.primary { border-color: var(--red); background: var(--red); color: white; }
.button.primary:hover:not(:disabled) { background: var(--red-dark); }
.button.success { border-color: #bbf7d0; background: #dcfce7; color: #166534; }
.button.ghost { background: transparent; }

.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.dashboard-card {
  position: relative; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 18px;
  min-height: 150px; padding: 24px; border: 1px solid var(--border); border-radius: 20px;
  background: var(--surface); box-shadow: var(--shadow); transition: transform .15s ease, border-color .15s ease;
}
.dashboard-card:hover { transform: translateY(-2px); border-color: #c8d0da; }
.dashboard-card h2 { margin: 0 0 7px; }
.dashboard-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.dashboard-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; background: #fee2e2; color: #991b1b; font-size: 12px; font-weight: 900; }
.card-arrow { color: #94a3b8; font-size: 26px; }

.auth-page { display: grid; place-items: center; background: linear-gradient(140deg, #f9fafb, #eceff3); }
.auth-shell { width: min(440px, calc(100% - 30px)); padding: 32px 0; }
.auth-card { padding: 30px; border: 1px solid var(--border); border-radius: 24px; background: white; box-shadow: 0 24px 70px rgba(15,23,42,.12); }
.auth-copy { margin: 32px 0 22px; }
.auth-copy h2 { margin: 0 0 7px; font-size: 28px; }
.auth-copy p { margin: 0; color: var(--muted); }
.form-stack { display: grid; gap: 16px; }
.form-stack label, .filter-card label, .invoice-fields label { display: grid; gap: 6px; }
.form-stack label > span, .filter-card label > span, .invoice-fields label > span { color: #4b5563; font-size: 11px; font-weight: 800; letter-spacing: .03em; }
input, select {
  width: 100%; min-height: 39px; padding: 8px 10px; border: 1px solid #cfd6df; border-radius: 9px;
  outline: none; background: white; color: var(--text);
}
input:focus, select:focus { border-color: #64748b; box-shadow: 0 0 0 3px rgba(100,116,139,.1); }
.form-error { margin: 0; padding: 10px 12px; border-radius: 9px; background: #fef2f2; color: #b91c1c; font-size: 13px; }

.filter-card {
  display: grid; grid-template-columns: minmax(240px, 2fr) repeat(5, minmax(120px, 1fr)); gap: 12px;
  padding: 16px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); margin-bottom: 18px;
}

.notice { margin: 0 0 16px; padding: 11px 14px; border: 1px solid #dbe2ea; border-radius: 11px; background: #f8fafc; color: #475569; font-size: 13px; }
.notice.success { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.notice.warning { border-color: #fde68a; background: #fffbeb; color: #92400e; }
.notice.error { border-color: #fecaca; background: #fef2f2; color: #b91c1c; }

.invoice-workspace { display: grid; grid-template-columns: minmax(310px, 390px) minmax(0, 1fr); gap: 18px; align-items: start; }
.invoice-list-panel, .invoice-detail { border: 1px solid var(--border); border-radius: 17px; background: white; box-shadow: 0 10px 30px rgba(15,23,42,.04); overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 18px; border-bottom: 1px solid var(--border); }
.panel-heading h2 { margin: 0; font-size: 17px; }
.panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.invoice-list { max-height: calc(100vh - 295px); overflow-y: auto; }
.invoice-row {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 15px 17px;
  border: 0; border-bottom: 1px solid #edf0f3; background: white; text-align: left;
}
.invoice-row:hover { background: #f8fafc; }
.invoice-row.selected { background: #fff7f7; box-shadow: inset 3px 0 0 var(--red); }
.invoice-row-main, .invoice-row-meta { display: grid; gap: 4px; }
.invoice-row-main strong { font-size: 14px; }
.invoice-row-main span { color: #334155; font-size: 12px; }
.invoice-row-main small { color: var(--muted); }
.invoice-row-meta { justify-items: end; align-content: start; color: var(--muted); font-size: 11px; text-align: right; }
.invoice-row-meta > strong { color: var(--text); font-size: 14px; }
.list-empty { padding: 28px 18px; color: var(--muted); text-align: center; }

.invoice-detail { position: sticky; top: 90px; min-height: 320px; padding: 20px; }
.invoice-detail.empty-state { display: grid; place-items: center; min-height: 420px; color: var(--muted); text-align: center; }
.invoice-detail.empty-state h2 { color: var(--text); }
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.detail-header h2 { margin: 0; font-size: 24px; }
.detail-actions, .detail-badges { display: flex; gap: 7px; flex-wrap: wrap; }
.detail-badges { margin-top: 9px; }
.badge { display: inline-flex; padding: 4px 7px; border-radius: 999px; background: #eef2f7; color: #475569; font-size: 9px; font-weight: 850; text-transform: uppercase; letter-spacing: .05em; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.success { background: #dcfce7; color: #166534; }

.invoice-fields { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); gap: 10px; margin: 16px 0; }
.line-editor-wrap { width: 100%; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.line-editor { width: max(1180px, 100%); border-collapse: collapse; font-size: 11px; }
.line-editor th { position: sticky; top: 0; z-index: 2; padding: 8px; background: #f1f5f9; color: #475569; text-align: left; white-space: nowrap; }
.line-editor td { padding: 5px; border-top: 1px solid #edf0f3; vertical-align: middle; }
.line-editor input { min-height: 31px; padding: 5px 7px; border-radius: 6px; font-size: 11px; }
.line-editor td:nth-child(1) input { width: 90px; }
.line-editor td:nth-child(2) input { width: 115px; }
.line-editor td:nth-child(3) input { width: 180px; }
.line-editor td:nth-child(4) input { width: 100px; }
.line-editor td:nth-child(n+5):nth-child(-n+11) input { width: 74px; }
.confidence { font-weight: 800; color: #166534; white-space: nowrap; }
.confidence.low { color: #b45309; }
.detail-footer { display: flex; justify-content: flex-end; gap: 9px; margin-top: 15px; }

@media (max-width: 1050px) {
  .filter-card { grid-template-columns: repeat(3, 1fr); }
  .filter-search { grid-column: span 2; }
  .invoice-workspace { grid-template-columns: 1fr; }
  .invoice-list { max-height: 420px; }
  .invoice-detail { position: static; }
  .invoice-fields { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
}

@media (max-width: 680px) {
  .topbar { min-height: 62px; padding: 8px 12px; }
  .brand-lockup.compact { min-width: 0; }
  .brand-lockup.compact .eyebrow, .user-name { display: none; }
  .store-mark.small { width: 42px; height: 42px; }
  .page-shell { width: min(100% - 22px, 1400px); padding-top: 24px; }
  .split-heading { align-items: flex-start; flex-direction: column; }
  .filter-card { grid-template-columns: 1fr 1fr; padding: 12px; }
  .filter-search { grid-column: 1 / -1; }
  .invoice-row { grid-template-columns: 1fr; }
  .invoice-row-meta { justify-items: start; text-align: left; }
  .invoice-fields { grid-template-columns: 1fr 1fr; }
  .detail-header { flex-direction: column; }
  .detail-footer { align-items: stretch; flex-direction: column; }
  .detail-footer .button { width: 100%; }
  .auth-card { padding: 22px; }
}
