:root {
  --bg-page: #f4f6f9;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-header: rgba(255, 255, 255, 0.92);
  --bg-hover: #eef2ff;
  --bg-pill: #f1f5f9;
  --bg-pill-active: #ffffff;
  --bg-table-head: #f8fafc;
  --bg-record: #ffffff;
  --bg-record-metric: #f8fafc;
  --bg-drawer: #ffffff;
  --bg-user-chip: #f8fafc;
  --bg-muted: #f4f6f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --success: #059669;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --header-h: 64px;
  --sidebar-w: 260px;
  --font: 'DM Sans', system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg-page: #0b1220;
  --bg-card: #151f2e;
  --bg-input: #1c2838;
  --bg-header: rgba(21, 31, 46, 0.94);
  --bg-hover: #243044;
  --bg-pill: #1c2838;
  --bg-pill-active: #243044;
  --bg-table-head: #1a2535;
  --bg-record: #1a2535;
  --bg-record-metric: #243044;
  --bg-drawer: #151f2e;
  --bg-user-chip: #1c2838;
  --bg-muted: #0b1220;
  --border: #2d3a4f;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] .flash-ok {
  background: #064e3b;
  border-color: #047857;
  color: #a7f3d0;
}

[data-theme="dark"] .flash-error {
  background: #450a0a;
  border-color: #991b1b;
  color: #fecaca;
}

[data-theme="dark"] .badge {
  background: #312e81;
  color: #c7d2fe;
}

[data-theme="dark"] .badge-muted {
  background: #243044;
  color: #94a3b8;
}

[data-theme="dark"] .btn-dark {
  background: #334155;
}

[data-theme="dark"] .btn-dark:hover {
  background: #475569;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-page);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

img, svg { display: block; max-width: 100%; }

/* Auth pages */
.auth-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.auth-card {
  width: 100%;
  max-width: 546px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 2.25rem;
  font-size: 1.05rem;
}

.auth-card h2 {
  font-size: 1.45rem;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.95rem;
  margin-bottom: 1.85rem;
}

.auth-logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
}

.auth-card .input,
.auth-card .btn {
  font-size: 1rem;
  padding: 0.85rem 1rem;
}

.password-wrap {
  position: relative;
}

.password-wrap .input {
  padding-right: 3rem;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 0.55rem;
  transform: translateY(-50%);
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.password-toggle:hover {
  color: var(--text);
  background: var(--bg-muted);
}

.password-toggle svg {
  width: 1.15rem;
  height: 1.15rem;
}

.password-toggle .icon-eye-off {
  display: none;
}

.password-toggle.is-visible .icon-eye {
  display: none;
}

.password-toggle.is-visible .icon-eye-off {
  display: block;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.theme-toggle svg {
  width: 1.15rem;
  height: 1.15rem;
}

.theme-toggle .icon-moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

.theme-toggle-floating {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1rem;
}

@media (min-width: 1024px) {
  .app-header { padding: 0 1.5rem; }
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.app-brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
}

.app-body {
  flex: 1;
  display: flex;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.app-sidebar {
  display: none;
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 1.25rem 0 1.25rem 1.25rem;
}

@media (min-width: 1024px) {
  .app-sidebar { display: block; }
}

.sidebar-nav {
  position: sticky;
  top: calc(var(--header-h) + 1rem);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  box-shadow: var(--shadow);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 0.925rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover,
.sidebar-link.is-active {
  background: var(--bg-hover);
  color: var(--primary);
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 1rem;
}

@media (min-width: 768px) {
  .app-main { padding: 1.25rem 1.5rem 2rem; }
}

/* Mobile nav drawer */
.mobile-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  cursor: pointer;
}

[data-theme="dark"] .mobile-nav-btn {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #0f172a;
}

@media (min-width: 1024px) {
  .mobile-nav-btn { display: none; }
}

.mobile-drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.mobile-drawer.is-open {
  pointer-events: auto;
  opacity: 1;
}

.mobile-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.mobile-drawer-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: min(300px, 88vw);
  height: 100%;
  background: var(--bg-card);
  padding: 1rem;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  box-shadow: var(--shadow);
}

.mobile-drawer.is-open .mobile-drawer-panel {
  transform: translateX(0);
}

/* Components */
.page-title {
  font-size: clamp(1.35rem, 2.5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}

.page-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.925rem;
}

.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.section-card-header {
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.section-card-body { padding: 1.15rem; }

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

@media (min-width: 640px) {
  .form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 900px) {
  .form-grid.cols-buyer { grid-template-columns: repeat(5, 1fr); align-items: end; }
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}

.checkbox-field input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
}

.input-sm {
  padding: 0.4rem 0.55rem;
  font-size: 0.85rem;
}

.input,
.select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  color: var(--text);
  background: var(--bg-input);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1.1rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.925rem;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:active { transform: scale(0.98); }

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

.btn-dark { background: #0f172a; color: #fff; }
.btn-dark:hover { background: #1e293b; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }

.btn-ghost {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-sm { padding: 0.45rem 0.75rem; font-size: 0.85rem; }

.btn-block { width: 100%; }

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.flash {
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  border: 1px solid;
  font-size: 0.925rem;
}

.flash-ok {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}

.flash-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1280px) {
  .stat-grid.stats-7 { grid-template-columns: repeat(7, 1fr); }
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  margin-top: 0.35rem;
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-value.positive { color: var(--success); }
.stat-value.negative { color: var(--danger); }

.pill-group {
  display: inline-flex;
  padding: 0.2rem;
  background: var(--bg-pill);
  border-radius: 999px;
  border: 1px solid var(--border);
}

.pill {
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.pill.is-active {
  background: var(--bg-pill-active);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--bg-hover);
  color: var(--primary);
}

.badge-muted {
  background: var(--bg-pill);
  color: var(--text-muted);
}

/* Tables desktop */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 0.8rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: var(--bg-table-head);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

.data-table tbody tr:hover { background: var(--bg-hover); }

/* Mobile cards instead of table */
.mobile-cards { display: grid; gap: 0.75rem; }

@media (min-width: 768px) {
  .mobile-cards { display: none; }
}

.desktop-table { display: none; }

@media (min-width: 768px) {
  .desktop-table { display: block; }
}

.record-card {
  background: var(--bg-record);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}

.record-card-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  word-break: break-word;
}

.record-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}

.record-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.record-metric {
  background: var(--bg-record-metric);
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  text-align: center;
}

.record-metric span {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.record-metric strong {
  font-size: 0.9rem;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.user-chip {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.65rem;
  background: var(--bg-user-chip);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
}

@media (min-width: 640px) {
  .user-chip { display: flex; }
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 700;
}

.status-ok {
  background: rgba(5, 150, 105, 0.12);
  color: var(--success);
}

.status-error {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
}

.status-muted {
  background: var(--bg-pill);
  color: var(--text-muted);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.info-card {
  background: var(--bg-record);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.onboarding-target {
  position: relative;
  z-index: 121;
}

.onboarding-target.is-highlighted {
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.28), 0 0 26px rgba(79, 70, 229, 0.48);
}

.onboarding-overlay[hidden] {
  display: none;
}

.onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
}

.onboarding-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.62);
}

.onboarding-popover {
  position: fixed;
  width: min(320px, calc(100vw - 2rem));
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: var(--shadow);
  z-index: 122;
}

.onboarding-arrow {
  position: absolute;
  top: -10px;
  left: 28px;
  width: 18px;
  height: 18px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  transform: rotate(45deg);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
