/* =============================================================================
   Dropshipping Profit & Ad Spend Calculator — stylesheet
   One accent colour plus neutrals, a real type scale, one card/shadow system.
   Light and dark themes are driven by [data-theme] on <html>.
   ========================================================================== */

/* --- Design tokens: light ------------------------------------------------- */
:root {
  --accent:          #4f46e5;
  --accent-strong:   #4338ca;
  --accent-soft:     #eef2ff;
  --accent-contrast: #ffffff;

  --pos:      #047857;
  --pos-soft: #ecfdf5;
  --neg:      #b91c1c;
  --neg-soft: #fef2f2;
  --warn:     #b45309;
  --warn-soft:#fffbeb;

  --bg:        #f6f7fb;
  --surface:   #ffffff;
  --surface-2: #f9fafb;
  --border:    #e5e7eb;
  --border-strong: #d1d5db;

  --text:     #111827;
  --text-2:   #4b5563;
  --text-3:   #6b7280;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow:    0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);

  --radius:    14px;
  --radius-sm: 9px;

  --sidebar-w: 244px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  color-scheme: light;
}

/* --- Design tokens: dark -------------------------------------------------- */
[data-theme="dark"] {
  --accent:          #818cf8;
  --accent-strong:   #a5b4fc;
  --accent-soft:     #1e1b4b;
  --accent-contrast: #0b1020;

  --pos:      #34d399;
  --pos-soft: #052e23;
  --neg:      #f87171;
  --neg-soft: #3b0d0d;
  --warn:     #fbbf24;
  --warn-soft:#3a2a06;

  --bg:        #0b0f1a;
  --surface:   #121826;
  --surface-2: #171f30;
  --border:    #253048;
  --border-strong: #33405c;

  --text:     #e8edf7;
  --text-2:   #a9b4c9;
  --text-3:   #7f8ca6;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 1px 3px rgba(0, 0, 0, .5);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, .55);

  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.011em; font-weight: 650; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: .98rem; }
p  { margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

svg { width: 20px; height: 20px; fill: currentColor; flex: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-contrast);
  padding: .6rem 1rem; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

/* --- Layout --------------------------------------------------------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem .85rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: .65rem; padding: .25rem .55rem 1.35rem; }
.brand-mark { font-size: 1.4rem; line-height: 1; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 1rem; letter-spacing: -.01em; }
.brand-text small { color: var(--text-3); font-size: .72rem; letter-spacing: .06em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: .7rem;
  padding: .58rem .6rem;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 520;
  font-size: .92rem;
  transition: background .13s ease, color .13s ease;
}
.nav-link svg { width: 18px; height: 18px; opacity: .8; }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav-link.is-active svg { opacity: 1; }

.sidebar-foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); display: grid; gap: .5rem; }

.theme-toggle {
  display: flex; align-items: center; gap: .7rem;
  width: 100%;
  padding: .55rem .6rem;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2);
  font: inherit; font-size: .9rem; cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }
.theme-toggle svg { width: 18px; height: 18px; }
[data-theme="light"] .icon-moon,
[data-theme="dark"]  .icon-sun { display: none; }

.user-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .2rem .6rem; }
.user-name {
  font-size: .84rem; color: var(--text-3); font-weight: 560;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.logout-link { font-size: .84rem; color: var(--text-3); }
.logout-link:hover { color: var(--neg); }

.main { flex: 1; min-width: 0; padding: 1.75rem clamp(1rem, 3vw, 2.25rem) 4rem; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.35rem;
}
.page-sub { color: var(--text-3); font-size: .9rem; margin-top: .2rem; }
.page-head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.nav-toggle {
  display: none;
  position: fixed; top: .7rem; left: .7rem; z-index: 60;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); cursor: pointer;
}

.scrim {
  display: none;
  position: fixed; inset: 0;
  background: rgba(4, 8, 18, .45);
  z-index: 35;
}

/* --- Cards ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.15rem 1.25rem;
}
.card + .card { margin-top: 1rem; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; flex-wrap: wrap; margin-bottom: .9rem;
}
.card-head h2 { font-size: 1rem; }
.card-note { color: var(--text-3); font-size: .82rem; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(430px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* --- KPI cards ------------------------------------------------------------ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(212px, 1fr));
  gap: .9rem;
  margin-bottom: 1.25rem;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem 1.05rem;
  display: flex; flex-direction: column; gap: .3rem;
}
.kpi-label {
  font-size: .76rem; font-weight: 620; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-3);
}
.kpi-value { font-size: 1.6rem; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-foot { display: flex; align-items: center; gap: .45rem; font-size: .8rem; color: var(--text-3); }
.kpi-accent .kpi-value { color: var(--accent-strong); }

.delta {
  display: inline-flex; align-items: center; gap: .2rem;
  font-size: .76rem; font-weight: 650;
  padding: .1rem .4rem; border-radius: 999px;
}
.delta-good { color: var(--pos); background: var(--pos-soft); }
.delta-bad  { color: var(--neg); background: var(--neg-soft); }
.delta-flat { color: var(--text-3); background: var(--surface-2); }

.num { font-variant-numeric: tabular-nums; }
.num-negative { color: var(--neg); }

.na {
  display: inline-block;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  padding: 0 .35rem;
  font-size: .8em;
  cursor: help;
}

/* --- Filter bar ----------------------------------------------------------- */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: .85rem 1rem;
  margin-bottom: 1.25rem;
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.preset-group { display: flex; flex-wrap: wrap; gap: .3rem; background: var(--surface-2); padding: .25rem; border-radius: 10px; }
.preset {
  border: 0; background: transparent; color: var(--text-2);
  font: inherit; font-size: .85rem; font-weight: 560;
  padding: .38rem .72rem; border-radius: 7px; cursor: pointer;
  white-space: nowrap;
}
.preset:hover { color: var(--text); }
.preset.is-active { background: var(--surface); color: var(--accent-strong); box-shadow: var(--shadow-sm); }
.filter-fields { display: flex; align-items: flex-end; gap: .6rem; flex-wrap: wrap; }

/* --- Forms ---------------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .9rem; }

.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field > span, .field > label { font-size: .82rem; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: .76rem; color: var(--text-3); font-weight: 400; }
.field-sm { max-width: 190px; }

input[type="text"], input[type="password"], input[type="number"], input[type="date"],
input[type="search"], select, textarea {
  width: 100%;
  font: inherit;
  font-size: .92rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: .55rem .7rem;
  transition: border-color .13s ease, box-shadow .13s ease;
  -webkit-appearance: none;
  appearance: none;
  min-height: 40px;
}
textarea { min-height: 78px; resize: vertical; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236b7280'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .45rem center;
  background-size: 20px;
  padding-right: 2rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
input[type="date"] { min-width: 150px; }
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1) opacity(.65); }

.input-prefixed { position: relative; }
.input-prefixed .prefix {
  position: absolute; left: .7rem; top: 50%; transform: translateY(-50%);
  color: var(--text-3); font-size: .9rem; pointer-events: none;
}
.input-prefixed input { padding-left: 1.75rem; }

.checkbox { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--text-2); }
.checkbox input { width: 16px; height: 16px; min-height: 0; accent-color: var(--accent); }

.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.1rem; }

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-size: .9rem; font-weight: 600;
  padding: .55rem 1rem;
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .13s ease, border-color .13s ease, color .13s ease;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--neg); border-color: transparent; }
.btn-danger:hover { background: var(--neg-soft); }
.btn-sm { font-size: .82rem; padding: .3rem .6rem; min-height: 32px; }
.btn-block { width: 100%; }

/* --- Tables --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; margin: 0 -1.25rem -1.15rem; padding: 0 1.25rem 1.15rem; }
table { width: 100%; border-collapse: collapse; font-size: .89rem; }
thead th {
  text-align: left;
  font-size: .74rem; font-weight: 680; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-3);
  padding: .5rem .65rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: .62rem .65rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.right, th.right { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap, th.nowrap { white-space: nowrap; }
tfoot td { padding: .62rem .65rem; border-top: 2px solid var(--border); font-weight: 680; }
.col-actions { width: 1%; white-space: nowrap; }
.muted { color: var(--text-3); }
.archived-row td { opacity: .62; }

/* --- Status pills --------------------------------------------------------- */
.pill {
  display: inline-block;
  font-size: .74rem; font-weight: 680; letter-spacing: .01em;
  padding: .16rem .52rem; border-radius: 999px;
  white-space: nowrap;
}
.pill-profitable { color: var(--pos); background: var(--pos-soft); }
.pill-losing     { color: var(--neg); background: var(--neg-soft); }
.pill-breakeven  { color: var(--warn); background: var(--warn-soft); }
.pill-na         { color: var(--text-3); background: var(--surface-2); }
.pill-archived   { color: var(--text-3); background: var(--surface-2); }

/* --- Break-even gauges ---------------------------------------------------- */
.gauge-list { display: grid; gap: .95rem; }
.gauge-head { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; font-size: .88rem; }
.gauge-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gauge-figures { color: var(--text-3); font-size: .8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.gauge-track {
  position: relative;
  height: 9px; margin-top: .35rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.gauge-fill { height: 100%; border-radius: 999px; transition: width .3s ease; }
.gauge-fill.is-profitable { background: var(--pos); }
.gauge-fill.is-losing     { background: var(--neg); }
.gauge-fill.is-breakeven  { background: var(--warn); }
.gauge-marker { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text-2); opacity: .75; }
.gauge-legend { font-size: .76rem; color: var(--text-3); margin-top: .15rem; }

/* --- Live preview panel (Products form) ----------------------------------- */
.preview {
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.preview h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--accent-strong); margin-bottom: .7rem; }
.preview-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; }
.preview-item { display: flex; flex-direction: column; gap: .1rem; }
.preview-item dt { font-size: .76rem; color: var(--text-2); font-weight: 560; }
.preview-item dd { margin: 0; font-size: 1.06rem; font-weight: 680; font-variant-numeric: tabular-nums; }
.preview-item dd.pos { color: var(--pos); }
.preview-item dd.neg { color: var(--neg); }

/* --- Charts --------------------------------------------------------------- */
.chart-box { position: relative; height: 300px; }
.chart-box.chart-sm { height: 250px; }

/* --- Flash / alerts ------------------------------------------------------- */
.flash {
  border-radius: var(--radius-sm);
  padding: .7rem .95rem;
  margin-bottom: 1rem;
  font-size: .9rem;
  border: 1px solid transparent;
}
.flash-success { background: var(--pos-soft); color: var(--pos); border-color: color-mix(in srgb, var(--pos) 30%, transparent); }
.flash-error   { background: var(--neg-soft); color: var(--neg); border-color: color-mix(in srgb, var(--neg) 30%, transparent); }
.flash-info    { background: var(--accent-soft); color: var(--accent-strong); border-color: color-mix(in srgb, var(--accent) 26%, transparent); }

.error-list { margin: 0 0 1rem; padding: .7rem .95rem .7rem 2rem; }
.error-list li { font-size: .9rem; }

.callout {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: .7rem .9rem;
  font-size: .85rem;
  color: var(--text-2);
  margin-bottom: 1rem;
}

/* --- Empty state ---------------------------------------------------------- */
.empty { text-align: center; padding: 3rem 1.5rem; color: var(--text-3); }
.empty-icon { font-size: 2.4rem; margin-bottom: .6rem; opacity: .75; }
.empty h2 { color: var(--text); margin-bottom: .35rem; }
.empty p { margin-bottom: 1.15rem; font-size: .92rem; }

/* --- Loading -------------------------------------------------------------- */
.is-loading { position: relative; min-height: 120px; }
.is-loading::after {
  content: "";
  position: absolute; inset: 0;
  background: var(--surface);
  opacity: .65;
}
.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 1.5rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  border-radius: 6px;
  height: 1em;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* --- Login ---------------------------------------------------------------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.auth-card {
  width: 100%; max-width: 394px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 2rem 1.85rem;
}
.auth-logo { font-size: 2rem; text-align: center; margin-bottom: .3rem; }
.auth-card h1 { font-size: 1.3rem; text-align: center; }
.auth-sub { text-align: center; color: var(--text-3); font-size: .89rem; margin: .3rem 0 1.5rem; }
.auth-card .field + .field { margin-top: .9rem; }
.auth-card .btn { margin-top: 1.25rem; }
.auth-foot { text-align: center; margin-top: 1.25rem; font-size: .8rem; color: var(--text-3); }

.auth-error {
  background: var(--neg-soft); color: var(--neg);
  border: 1px solid color-mix(in srgb, var(--neg) 30%, transparent);
  border-radius: var(--radius-sm);
  padding: .65rem .85rem; font-size: .88rem; margin-bottom: 1.1rem;
}

/* --- Responsive ----------------------------------------------------------- */
@media (max-width: 900px) {
  .nav-toggle { display: flex; }

  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
    width: 262px;
  }
  .sidebar.is-open { transform: translateX(0); }
  .scrim.is-open { display: block; }

  .main { padding-top: 3.9rem; }
  .page-head { margin-bottom: 1.1rem; }
  h1 { font-size: 1.35rem; }

  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: .7rem; }
  .kpi { padding: .8rem .9rem; }
  .kpi-value { font-size: 1.32rem; }

  .filter-bar { padding: .75rem .8rem; }
  .preset-group { width: 100%; }
  .preset { flex: 1 1 auto; text-align: center; }
  .filter-fields { width: 100%; }
  .field-sm { max-width: none; flex: 1 1 140px; }

  .card { padding: 1rem; border-radius: 12px; }
  .table-wrap { margin: 0 -1rem -1rem; padding: 0 1rem 1rem; }
  .chart-box { height: 260px; }
}

@media (max-width: 520px) {
  body { font-size: 14.5px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 1.2rem; }
  .form-grid { grid-template-columns: 1fr; }
  .btn { width: 100%; }
  .btn-sm { width: auto; }
  .page-head-actions { width: 100%; }
  .filter-fields { flex-direction: column; align-items: stretch; }
  /* In a column flex container a flex-basis applies to HEIGHT, so the 140px
     basis set at the tablet breakpoint would stretch each field into a tall
     block. Reset it here. */
  .filter-fields .field { flex: 0 0 auto; }
  .field-sm { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .sidebar, .nav-toggle, .filter-bar, .page-head-actions, .btn { display: none !important; }
  .main { padding: 0; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}
