/* ============================================================
   Plantstism · Sales — design tokens
   Dark is the brand's home (black streetwear + neon pink);
   light is a warm blush variant stepped from the same hues.
   ============================================================ */
:root {
  color-scheme: light;
  --bg: #fbf6f8;
  --bg-glow: rgba(236, 72, 153, 0.14);
  --surface: #ffffff;
  --surface-2: #f7eff3;
  --surface-3: #efe3ea;
  --border: #eadbe3;
  --border-strong: #d9c3cf;
  --text: #1e1720;
  --text-2: #5d4f5a;
  --text-3: #8a7a86;
  --accent: #d6246e;
  --accent-hover: #bd1b5f;
  --accent-soft: #fde5f0;
  --accent-ink: #ffffff;
  --accent-text: #b8195c;
  --good: #0f7a4f;
  --good-soft: #dcf3e7;
  --owed: #b4232f;
  --owed-soft: #fde3e5;
  --series-1: #db2777;
  --series-2: #2563eb;
  --shadow-sm: 0 1px 2px rgba(60, 20, 40, 0.06);
  --shadow: 0 1px 2px rgba(60, 20, 40, 0.05), 0 8px 28px -10px rgba(60, 20, 40, 0.14);
  --shadow-lg: 0 24px 60px -16px rgba(60, 20, 40, 0.35);
  --mascot-shadow: drop-shadow(0 18px 22px rgba(90, 20, 50, 0.22));
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #120e14;
  --bg-glow: rgba(255, 63, 164, 0.16);
  --surface: #1b161e;
  --surface-2: #231c27;
  --surface-3: #2d2432;
  --border: #2f2734;
  --border-strong: #43384a;
  --text: #f7eef4;
  --text-2: #c2b3bf;
  --text-3: #8f808c;
  --accent: #ff3fa4;
  --accent-hover: #ff64b6;
  --accent-soft: #3a1a2d;
  --accent-ink: #1a0712;
  --accent-text: #ff7cc0;
  --good: #4fd69c;
  --good-soft: #15302a;
  --owed: #ff7a85;
  --owed-soft: #3a1b21;
  --series-1: #e8388f;
  --series-2: #4f8ff7;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px -12px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 30px 70px -20px rgba(0, 0, 0, 0.8);
  --mascot-shadow: drop-shadow(0 22px 28px rgba(0, 0, 0, 0.55));
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #120e14;
    --bg-glow: rgba(255, 63, 164, 0.16);
    --surface: #1b161e;
    --surface-2: #231c27;
    --surface-3: #2d2432;
    --border: #2f2734;
    --border-strong: #43384a;
    --text: #f7eef4;
    --text-2: #c2b3bf;
    --text-3: #8f808c;
    --accent: #ff3fa4;
    --accent-hover: #ff64b6;
    --accent-soft: #3a1a2d;
    --accent-ink: #1a0712;
    --accent-text: #ff7cc0;
    --good: #4fd69c;
    --good-soft: #15302a;
    --owed: #ff7a85;
    --owed-soft: #3a1b21;
    --series-1: #e8388f;
    --series-2: #4f8ff7;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px -12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 30px 70px -20px rgba(0, 0, 0, 0.8);
    --mascot-shadow: drop-shadow(0 22px 28px rgba(0, 0, 0, 0.55));
  }
}

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

textarea { height: auto; padding: 12px 14px; line-height: 1.55; resize: vertical; }
textarea::placeholder { color: var(--text-3); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Components set their own display; the hidden attribute must still win. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 0;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.glow {
  position: fixed;
  inset: -20vh -10vw auto auto;
  width: 70vw;
  height: 70vh;
  background: radial-gradient(closest-side, var(--bg-glow), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.num, .stat-value, .sale-price, .summary-value, td.num { font-variant-numeric: tabular-nums; }

h1, h2, h3, p { margin: 0; }

code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 6px;
}

.i {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 28px 6px;
}

.brand img {
  display: block;
  height: 54px;
  width: auto;
  transition: transform 0.25s cubic-bezier(.2, .8, .2, 1);
}
.brand:hover img { transform: rotate(-3deg) scale(1.04); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.tabs a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--text-2);
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a .i { width: 16px; height: 16px; }
.tabs a[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 18px -6px var(--accent);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  font-size: 12.5px;
  color: var(--text-2);
  max-width: 52vw;
}
.status-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}
.status.ok .status-dot { background: var(--good); }
.status.ok .status-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--good);
  opacity: 0;
  animation: ping 2.4s ease-out infinite;
}
.status.err { border-color: var(--owed); color: var(--owed); background: var(--owed-soft); }
.status.err .status-dot { background: var(--owed); }
@keyframes ping { 0% { transform: scale(0.6); opacity: 0.7; } 80%, 100% { transform: scale(1.5); opacity: 0; } }

/* ============================================================
   Buttons & inputs
   ============================================================ */
button { font: inherit; color: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-block { width: 100%; }
.btn-sm { height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 20px -8px var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 10px 26px -8px var(--accent); }

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-2);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }

.btn-danger { background: var(--owed); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}
.icon-btn:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }

#themeToggle .i-sun { display: none; }
:root[data-theme="dark"] #themeToggle .i-sun { display: block; }
:root[data-theme="dark"] #themeToggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #themeToggle .i-sun { display: block; }
  :root:not([data-theme="light"]) #themeToggle .i-moon { display: none; }
}

.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

label, .label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.optional { font-weight: 400; color: var(--text-3); margin-left: 4px; }

input[type="text"], input[type="number"], input[type="date"], input[type="password"], input[type="datetime-local"], textarea {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  -moz-appearance: textfield;
}
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input::placeholder { color: var(--text-3); }
input:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 4px var(--accent-soft); }
input[aria-invalid="true"] { border-color: var(--owed); }
input[type="date"]::-webkit-calendar-picker-indicator, input[type="datetime-local"]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: 0.6; }
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator, :root[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator { filter: invert(1); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) input[type="date"]::-webkit-calendar-picker-indicator, :root:not([data-theme="light"]) input[type="datetime-local"]::-webkit-calendar-picker-indicator { filter: invert(1); }
}

.input-affix { position: relative; }
.input-affix .affix {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-weight: 600;
  pointer-events: none;
}
.input-affix input { padding-left: 32px; font-variant-numeric: tabular-nums; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 4px;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.segmented label { position: relative; margin: 0; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: grid;
  place-items: center;
  height: 34px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.segmented label:hover span { color: var(--text); }
.segmented input:checked + span { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--border); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

.toggles { display: flex; gap: 22px; flex-wrap: wrap; }
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  transition: background-color 0.18s ease, border-color 0.18s ease;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s cubic-bezier(.3, 1.4, .5, 1);
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.form-error {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--owed-soft);
  color: var(--owed);
  font-size: 13px;
  font-weight: 500;
}

/* ============================================================
   Layout
   ============================================================ */
.page {
  position: relative;
  z-index: 1;
  max-width: 1440px;
  margin: 0 auto;
  padding: 14px 28px 40px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  margin-top: 20px;
}
.col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.col-entry { position: sticky; top: 16px; }

.dash-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 10px 0 20px;
}
.dash-title {
  font-size: clamp(26px, 3vw, 34px);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.15;
  margin-top: 4px;
}
.dash-sub { font-size: 14px; color: var(--text-3); margin-top: 4px; }
.stats.kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpis .stat { background: var(--surface); box-shadow: var(--shadow); padding: 18px 20px; }
.kpis .stat-sub { white-space: normal; line-height: 1.45; }
@media (max-width: 1280px) { .stats.kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) { .stats.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.dash-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.range {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.range button {
  height: 32px;
  min-width: 48px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.range button:hover { background: var(--surface-2); color: var(--text); }
.range button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }

.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; }
.delta .i { width: 12px; height: 12px; stroke-width: 2.6; }
.delta.up { color: var(--good); }
.delta.down { color: var(--owed); }
.delta.flat { color: var(--text-2); }

.takeaways-card { margin-top: 20px; }
.takeaways {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 10px;
}
.takeaways li:not(.empty) {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-2);
}
.takeaways b { color: var(--text); font-weight: 700; }
.takeaways .empty { grid-column: 1 / -1; }
.tk-ic {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent-text);
}
.tk-ic .i { width: 15px; height: 15px; }

.card-note { font-size: 12.5px; color: var(--text-3); margin: -8px 0 10px; }

/* Sortable data tables */
.data-table tbody tr { cursor: default; }
.data-table th { padding: 0; }
.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 9px 8px;
  border: 0;
  background: none;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  cursor: pointer;
}
th.num .sort-btn { justify-content: flex-end; }
.sort-btn:hover, .sort-btn.is-active { color: var(--text); }
.sort-arrow { font-size: 8px; width: 8px; }
.data-table td strong { font-weight: 650; }
.data-table td.owes { color: var(--owed); font-weight: 700; }
.data-table td.muted { color: var(--text-3); }
.share-cell { min-width: 120px; }
.share-bar {
  display: inline-block;
  vertical-align: middle;
  width: 64px;
  height: 6px;
  margin-right: 8px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.share-fill { display: block; height: 100%; border-radius: 3px; background: var(--series-1); }
.kpis .stat-accent { background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%); }
.kpis .stat-ic { background: var(--accent-soft); border-color: transparent; }

.dash-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  align-items: stretch;
  margin-top: 20px;
}
.span-2 { grid-column: 1 / -1; }

@media (max-width: 820px) {
  .topbar { padding: 14px 16px 4px; flex-wrap: wrap; }
  .brand img { height: 44px; }
  .tabs { order: 3; width: 100%; }
  .tabs a { flex: 1; }
  .page { padding: 10px 16px 32px; }
  .grid, .dash-grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .dash-head .btn { width: 100%; }
  .col-entry { position: static; }
  .status-text { max-width: 34vw; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 22px;
  min-width: 0;
}
.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.005em;
  color: var(--text);
  margin-bottom: 16px;
}

.title-ic {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-text);
  flex-shrink: 0;
}
.title-ic .i { width: 16px; height: 16px; }

/* ============================================================
   Hero
   ============================================================ */
.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 16px;
  padding: 26px 30px;
  overflow: hidden;
  background:
    radial-gradient(120% 140% at 100% 0%, var(--accent-soft), transparent 55%),
    var(--surface);
}
.hero::before {
  content: "";
  position: absolute;
  right: -60px;
  bottom: -120px;
  width: 380px;
  height: 380px;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--bg-glow), transparent);
  pointer-events: none;
}
.hero-copy { position: relative; z-index: 1; display: flex; flex-direction: column; justify-content: center; gap: 6px; min-width: 0; }
.eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-text);
}
.hero-title {
  font-size: clamp(24px, 3.1vw, 36px);
  line-height: 1.12;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin-bottom: 18px;
  text-wrap: balance;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.stat {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  transition: transform 0.18s ease, border-color 0.18s ease;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  min-width: 0;
}
.stat:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.stat-ic {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-bottom: 8px;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent-text);
}
.stat-ic .i { width: 16px; height: 16px; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.stat-value {
  font-size: clamp(20px, 2.1vw, 26px);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-sub { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-owed.has-owed { background: var(--owed-soft); border-color: transparent; }
.stat-owed.has-owed .stat-value { color: var(--owed); }
.stat-owed.has-owed .stat-ic { color: var(--owed); background: transparent; }
.stat-accent {
  background: linear-gradient(135deg, var(--accent-soft), var(--surface-2) 70%);
  border-color: transparent;
}
.stat-accent .stat-value { color: var(--accent-text); }

.hero-art {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  margin: -28px -30px -28px 0;
  perspective: 900px;
}
.mascot {
  width: 100%;
  max-width: 220px;
  height: auto;
  filter: var(--mascot-shadow);
  transform-origin: 50% 90%;
  animation: bob 6.5s ease-in-out infinite;
  transition: transform 0.35s ease-out;
}
@keyframes bob {
  0%, 100% { translate: 0 6px; rotate: -0.8deg; }
  50% { translate: 0 -4px; rotate: 0.8deg; }
}

@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { grid-template-columns: minmax(0, 1fr) 210px; }
}
@media (max-width: 640px) {
  .hero { grid-template-columns: minmax(0, 1fr); padding: 22px 18px; }
  /* Keep the mascot inside the title band (head + shoulders only) so it never covers the stat cards. */
  .hero-art {
    position: absolute; right: -6px; top: 0; width: 124px; height: 108px; margin: 0;
    align-items: flex-start; overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent);
    mask-image: linear-gradient(to bottom, #000 72%, transparent);
  }
  .mascot { max-width: none; animation: none; }
  .hero-title { padding-right: 112px; margin-bottom: 14px; min-height: 2.24em; }
  .stat { padding: 12px 13px; }
}

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

/* ============================================================
   Day view
   ============================================================ */
.day-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.day-head .card-title { margin-bottom: 2px; font-size: 18px; }
.day-sub { font-size: 13px; color: var(--text-3); }
.day-nav { display: flex; align-items: center; gap: 6px; }
.day-nav input[type="date"] { width: 152px; height: 36px; border-radius: 10px; font-size: 13.5px; padding: 0 10px; }

.day-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 14px;
}
.summary-cell { background: var(--surface-2); padding: 12px 14px; min-width: 0; }
.summary-label { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.summary-value { display: block; font-size: 18px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary-value.accent { color: var(--accent-text); }

.sales { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sale {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.2s ease;
  animation: rise 0.28s cubic-bezier(.2, .8, .2, 1) both;
}
.sale:hover { border-color: var(--border-strong); background: var(--surface-2); }
.sale.is-new { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.sale-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 800;
  font-size: 16px;
}
.sale-main { min-width: 0; }
.sale-name { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sale-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; font-size: 12.5px; color: var(--text-3); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-2);
  white-space: nowrap;
}
.chip-var { background: var(--good-soft); color: var(--good); }
.chip-owed { background: var(--owed-soft); color: var(--owed); }
.chip-paid { background: var(--good-soft); color: var(--good); }

.sale-side { display: flex; align-items: center; gap: 10px; }
.sale-price { font-weight: 750; font-size: 16px; white-space: nowrap; }
.sale-actions { display: flex; gap: 4px; }
.sale-actions .icon-btn { width: 32px; height: 32px; border-radius: 9px; background: transparent; border-color: transparent; }
.sale-actions .icon-btn:hover { background: var(--surface-3); border-color: var(--border); }
.sale-actions .icon-btn.danger:hover { color: var(--owed); background: var(--owed-soft); }
.sale-actions .icon-btn.paid-on { color: var(--good); }
.sale-actions .icon-btn.paid-off { color: var(--owed); }
.sale-actions .i { width: 16px; height: 16px; }

@media (max-width: 520px) {
  .sale { grid-template-columns: 34px minmax(0, 1fr); }
  .sale-avatar { width: 34px; height: 34px; font-size: 14px; }
  .sale-side { grid-column: 2; justify-content: space-between; }
  .day-summary { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .day-summary .summary-cell:first-child { grid-column: 1 / -1; }
  .day-nav { width: 100%; }
  .day-nav input[type="date"] { flex: 1; width: auto; }
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 12px;
  text-align: center;
  color: var(--text-3);
  font-size: 13.5px;
  border: 1px dashed var(--border-strong);
  border-radius: 14px;
}
.empty strong { color: var(--text-2); font-size: 14px; }
.empty-sm { padding: 16px 12px; }

/* History table */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; transition: background-color 0.12s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.is-current { background: var(--accent-soft); }
tbody tr.is-current td:first-child { color: var(--accent-text); font-weight: 700; }
tbody tr:last-child td { border-bottom: none; }
.more-btn { margin-top: 10px; }

/* Unpaid */
.owed-group { padding: 12px 0; border-bottom: 1px solid var(--border); }
.owed-group:first-child { padding-top: 0; }
.owed-group:last-child { border-bottom: none; padding-bottom: 0; }
.owed-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.owed-name { font-weight: 650; display: flex; align-items: center; gap: 8px; min-width: 0; }
.owed-name span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.owed-initial {
  width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--owed-soft); color: var(--owed); font-size: 12px; font-weight: 800;
}
.owed-total { font-weight: 750; color: var(--owed); font-variant-numeric: tabular-nums; }
.owed-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 3px 0 3px 34px; font-size: 13px; color: var(--text-2); }
.owed-item-text { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.owed-item-text small { color: var(--text-3); margin-left: 4px; }
.pay-btn {
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--good);
  background: transparent;
  color: var(--good);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease;
}
.pay-btn:hover { background: var(--good-soft); }
.owed-head-side { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.bill-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 10px 0 8px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent-text);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.bill-btn .i { width: 14px; height: 14px; }
.bill-btn:hover { background: var(--accent-soft); }

/* Bill dialog */
.bill-modal { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
.bill-fieldset { border: 0; margin: 0; padding: 0; }
.bill-fieldset legend { padding: 0; margin-bottom: 7px; }
.bill-items { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 12px; max-height: 190px; overflow-y: auto; }
.bill-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.bill-item + .bill-item { border-top: 1px solid var(--border); }
.bill-item input { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }
.bill-item-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.bill-item-name small { color: var(--text-3); font-weight: 400; margin-left: 4px; }
.bill-item-price { font-weight: 700; font-variant-numeric: tabular-nums; }
.bill-preview {
  display: grid;
  place-items: center;
  min-height: 160px;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface-2);
}
.bill-preview img { display: block; width: 100%; max-width: 300px; border-radius: 10px; box-shadow: var(--shadow); }
.bill-preview:not(:has(img[src])) img { display: none; }
.bill-preview.is-empty::before { content: attr(data-empty); color: var(--text-3); font-size: 13px; }
.bill-actions { flex-wrap: wrap; }

/* ============================================================
   Charts
   ============================================================ */
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.chart-head .card-title { margin-bottom: 0; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.key-line { width: 14px; height: 3px; border-radius: 2px; }
.key-1 { background: var(--series-1); }
.key-2 { background: var(--series-2); }

.chart { position: relative; min-height: 180px; }
.chart svg { display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .baseline { stroke: var(--border-strong); stroke-width: 1; }
.chart .axis { fill: var(--text-3); font-size: 11px; font-family: inherit; font-variant-numeric: tabular-nums; }
.chart .axis-strong { fill: var(--text-2); font-weight: 600; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit-band { fill: var(--text); opacity: 0; transition: opacity 0.12s ease; }
.chart .col-group:hover .hit-band, .chart .col-group:focus .hit-band { opacity: 0.05; }
.chart .col-group:focus { outline: none; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: 0.12; }
.chart .ring { fill: var(--surface); }
.chart .crosshair { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.chart .end-label { fill: var(--text-2); font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; }

.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; }
.bar-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px; }
.bar-rank { font-size: 11px; font-weight: 800; color: var(--text-3); width: 14px; }
.bar-value { font-size: 13px; font-weight: 700; color: var(--text-2); font-variant-numeric: tabular-nums; }
.bar-track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--series-1);
  transform-origin: left;
  animation: grow 0.6s cubic-bezier(.2, .8, .2, 1) both;
}
.bar-fill.alt { background: var(--series-2); }
.bar-row:hover .bar-fill { filter: brightness(1.12); }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* Sales mix */
.mix + .mix { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.mix-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); margin-bottom: 10px; }
.mix-bar { display: flex; gap: 3px; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.mix-seg { flex-basis: 0; min-width: 4px; transform-origin: left; animation: grow 0.6s cubic-bezier(.2, .8, .2, 1) both; }
.mix-1 { background: var(--series-1); }
.mix-2 { background: var(--series-2); }
.mix-3 { background: var(--text-3); }
.mix-legend { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mix-legend li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto 40px; align-items: center; gap: 10px; font-size: 13px; }
.mix-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mix-count { color: var(--text-3); font-variant-numeric: tabular-nums; }
.mix-legend b { font-variant-numeric: tabular-nums; }
.mix-pct { text-align: right; color: var(--text-2); font-weight: 700; font-variant-numeric: tabular-nums; }

.tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  min-width: 150px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
}
.tt-title { font-size: 11.5px; font-weight: 700; color: var(--text-3); margin-bottom: 6px; }
.tt-row { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.tt-row + .tt-row { margin-top: 3px; }
.tt-row b { margin-left: auto; padding-left: 14px; color: var(--text); font-variant-numeric: tabular-nums; }

/* ============================================================
   Dialogs & toasts
   ============================================================ */
.modal {
  width: min(480px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.modal-sm { width: min(380px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(10, 4, 10, 0.55); backdrop-filter: blur(3px); }
.modal[open] { animation: pop 0.22s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.97); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head .card-title { margin: 0; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.confirm-text { color: var(--text-2); font-size: 14px; margin-top: -8px; }

.toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: calc(100vw - 32px);
}
.toast {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 460px;
  padding: 11px 16px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s cubic-bezier(.2, .9, .3, 1.2) both;
}
.toast.err { background: var(--owed); color: #fff; }
.toast.leaving { animation: toast-out 0.25s ease forwards; }
.toast .i { width: 16px; height: 16px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

.foot {
  margin-top: 28px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-3);
}

/* ============================================================
   Photos
   ============================================================ */
.photo-field { position: relative; }
.photo-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.photo-drop {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.photo-drop .i { width: 22px; height: 22px; color: var(--accent-text); }
.photo-drop span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.photo-drop strong { font-size: 13.5px; font-weight: 650; color: var(--text); }
.photo-drop small { font-size: 12px; color: var(--text-3); }
.photo-drop:hover, .photo-field.is-drag .photo-drop { border-color: var(--accent); background: var(--accent-soft); }
.photo-input:focus-visible + .photo-drop { outline: 2px solid var(--accent); outline-offset: 2px; }
.photo-drop[hidden], .photo-preview[hidden] { display: none; }

.photo-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.photo-preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 9px;
  background: var(--surface-3);
  flex-shrink: 0;
}
.photo-preview-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.photo-preview-actions .i { width: 14px; height: 14px; }

.sale-avatar.has-photo {
  padding: 0;
  border: 0;
  overflow: hidden;
  cursor: zoom-in;
  background: var(--surface-3);
}
.sale-avatar.has-photo img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.2s ease; }
.sale-avatar.has-photo:hover img { transform: scale(1.08); }

.lightbox {
  width: auto;
  max-width: min(900px, calc(100vw - 32px));
  padding: 10px;
  cursor: zoom-out;
}
.lightbox img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 120px);
  margin: 0 auto;
  border-radius: 14px;
}
.lightbox-caption { padding: 10px 6px 4px; text-align: center; font-size: 13.5px; font-weight: 600; color: var(--text-2); }

.name-cell { display: inline-flex; align-items: center; gap: 10px; }
.tbl-thumb {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* Four page tabs need to squeeze on phones. */
@media (max-width: 560px) {
  .tabs a { padding: 8px 6px; gap: 5px; font-size: 12.5px; }
  .tabs a .i { width: 14px; height: 14px; }
}
@media (max-width: 460px) {
  .tabs a .i { display: none; }
}

/* ============================================================
   Resale
   ============================================================ */
.select {
  height: 42px;
  min-width: 190px;
  padding: 0 36px 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a7a86' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 14px center;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  appearance: none;
  cursor: pointer;
}
.select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.resale-log { margin-top: 20px; }
.btn-soft { background: var(--accent-soft); color: var(--accent-text); }
.btn-soft:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); }
.data-table .btn-sm { height: 30px; font-size: 12.5px; }

.gain { color: var(--good); font-weight: 700; }
.loss { color: var(--owed); font-weight: 700; }
.flat { color: var(--text-2); font-weight: 700; }
.muted { color: var(--text-3); }
.stat-value.gain, .stat-value.loss { font-weight: 800; }

.key-gain { background: var(--good); }
.key-loss { background: var(--owed); }

/* Diverging bars */
.div-bars { display: flex; flex-direction: column; gap: 12px; }
.div-row {
  display: grid;
  grid-template-columns: minmax(90px, 150px) minmax(0, 1fr) 76px;
  align-items: center;
  gap: 12px;
  border-radius: 10px;
  outline: none;
}
.div-row:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.div-name { display: flex; flex-direction: column; min-width: 0; font-size: 13.5px; font-weight: 650; }
.div-name small { font-size: 11.5px; font-weight: 500; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.div-track { display: grid; grid-template-columns: 1fr 1fr; height: 14px; }
.div-bars.no-loss .div-track { grid-template-columns: 0 1fr; }
.div-half { position: relative; background: var(--surface-2); }
.div-neg { border-radius: 7px 0 0 7px; border-right: 2px solid var(--border-strong); }
.div-pos { border-radius: 0 7px 7px 0; }
.div-bars.no-loss .div-pos { border-radius: 7px; }
.div-bars.no-loss .div-neg { border: 0; }
.div-fill { position: absolute; top: 0; bottom: 0; animation: grow 0.6s cubic-bezier(.2, .8, .2, 1) both; }
.div-fill.gain { left: 0; background: var(--good); border-radius: 0 4px 4px 0; }
.div-fill.loss { right: 0; background: var(--owed); border-radius: 4px 0 0 4px; transform-origin: right; }
.div-row:hover .div-fill { filter: brightness(1.12); }
.div-value { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }

/* Scatter */
.chart .profit-zone { fill: var(--good); opacity: 0.06; }
.chart .break-even { stroke: var(--text-3); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .zone-label { fill: var(--text-3); font-size: 11px; font-weight: 600; }
.chart .dot { cursor: pointer; outline: none; }
.chart .dot:hover circle:last-child, .chart .dot:focus circle:last-child { r: 7; }

/* Resale dialog */
.resale-context {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.resale-context img, .resale-initial {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}
.resale-initial { display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); font-weight: 800; }
.resale-context span { display: flex; flex-direction: column; min-width: 0; }
.resale-context small { font-size: 12.5px; color: var(--text-3); }
.resale-preview:empty { display: none; }
.resale-preview {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface-2);
}
.resale-preview.gain { background: var(--good-soft); }
.resale-preview.loss { background: var(--owed-soft); }
.resale-preview.gain b { color: var(--good); }
.resale-preview.loss b { color: var(--owed); }
.modal-actions .spacer { flex: 1; }
.danger-text { color: var(--owed); }
.danger-text:hover:not(:disabled) { background: var(--owed-soft) !important; color: var(--owed) !important; }

@media (max-width: 560px) {
  .div-row { grid-template-columns: minmax(70px, 100px) minmax(0, 1fr) 64px; gap: 8px; }
  .select { width: 100%; }
  .dash-actions { width: 100%; }
}

/* ============================================================
   News
   ============================================================ */
.news-refresh .i { transition: transform 0.2s ease; }
.news-refresh.is-spinning .i { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.news-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.news-topics { flex-wrap: wrap; }
.news-topics button { min-width: 0; padding: 0 14px; }
.news-search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  min-width: 240px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--text-3);
}
.news-search:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.news-search input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 14px; outline: none; }

.news-banner {
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--owed-soft);
  color: var(--owed);
  font-size: 13.5px;
  font-weight: 600;
}

.news-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.news-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 170px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.news-card:hover { transform: translateY(-3px); border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
.news-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.news-card.featured {
  grid-column: 1 / -1;
  min-height: 0;
  padding: 28px 30px;
  background:
    radial-gradient(120% 160% at 100% 0%, var(--accent-soft), transparent 60%),
    var(--surface);
}
.news-meta { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 12.5px; color: var(--text-3); }
.news-source { font-weight: 700; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot-sep { color: var(--border-strong); }
.news-meta time { white-space: nowrap; }
.src-badge {
  --hue: 330;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 800;
  background: hsl(var(--hue) 70% 50% / 0.16);
  color: hsl(var(--hue) 55% 42%);
}
:root[data-theme="dark"] .src-badge { color: hsl(var(--hue) 80% 72%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .src-badge { color: hsl(var(--hue) 80% 72%); } }
.news-title {
  flex: 1;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: -0.01em;
  text-wrap: pretty;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.news-card.featured .news-title { font-size: clamp(20px, 2.2vw, 27px); line-height: 1.25; letter-spacing: -0.02em; -webkit-line-clamp: 3; }
.news-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--text-3); }
.news-open { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--accent-text); opacity: 0; transition: opacity 0.15s ease; }
.news-open .i { width: 13px; height: 13px; }
.news-card:hover .news-open, .news-card:focus-visible .news-open { opacity: 1; }
@media (hover: none) { .news-open { opacity: 1; } }

.news-empty { padding: 48px 16px; }
.news-empty .btn { margin-top: 8px; }

.news-card.skeleton { pointer-events: none; }
.news-card.skeleton span { display: block; height: 14px; border-radius: 7px; background: var(--surface-2); animation: pulse 1.2s ease-in-out infinite; }
.news-card.skeleton span:nth-child(1) { width: 40%; }
.news-card.skeleton span:nth-child(2) { width: 95%; height: 20px; }
.news-card.skeleton span:nth-child(3) { width: 70%; height: 20px; }
@keyframes pulse { 50% { opacity: 0.45; } }

@media (max-width: 560px) {
  .news-search { min-width: 0; width: 100%; }
  .news-card.featured { padding: 22px 20px; }
}

/* ============================================================
   Shipping
   ============================================================ */
.stats.kpis.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 640px) { .stats.kpis.kpis-3 { grid-template-columns: minmax(0, 1fr); } }
.ship-card { margin-top: 20px; }

.addr-cell { display: flex; align-items: flex-start; gap: 8px; min-width: 200px; max-width: 320px; }
.addr-text { flex: 1; font-size: 13px; line-height: 1.45; white-space: normal; color: var(--text-2); }
.addr-phone { display: block; font-weight: 650; color: var(--text); }
.addr-copy { flex: none; width: 30px; height: 30px; border-radius: 9px; }
.addr-copy .i { width: 15px; height: 15px; }
.cust-note { display: block; margin-top: 2px; font-size: 12px; color: var(--text-3); white-space: normal; }
.ship-age { font-size: 12px; white-space: nowrap; }
#customerForm textarea { height: auto; min-height: 112px; }
#customerForm input[readonly] { color: var(--text-2); background: var(--surface-2); cursor: default; }

/* Five page tabs: let the bar scroll sideways on the narrowest phones rather than overflow. */
@media (max-width: 460px) {
  .tabs { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex: none; padding: 8px 9px; }
}

/* Shipping on phones: each table row becomes a card, so buttons and addresses fit without sideways scrolling. */
@media (max-width: 640px) {
  .stats.kpis.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .kpis-3 .stat { padding: 12px; }
  .kpis-3 .stat-ic { display: none; }
  .kpis-3 .stat-value { font-size: 20px; }
  .kpis-3 .stat-sub { font-size: 11px; }

  .ship-card .table-wrap { overflow: visible; margin: 0; }
  .ship-card thead { display: none; }
  .ship-card table, .ship-card tbody { display: block; }
  .ship-card tbody tr { display: grid; gap: 8px 12px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--border); }
  .ship-card tbody tr:hover { background: none; }
  .ship-card tbody tr:last-child { border-bottom: none; }
  .ship-card td { display: block; padding: 0; border: 0; white-space: normal; text-align: left; min-width: 0; }
  .ship-card .addr-cell { min-width: 0; max-width: none; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
  .ship-card .data-table .btn-sm { height: 38px; padding: 0 14px; font-size: 13px; }
  .ship-card .more-btn { width: 100%; }

  /* Orders: cactus + price / customer + date / address / status + button */
  .ship-card #orderTable tr { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name price" "who when" "addr addr" "status action"; }
  .ship-card #orderTable td:nth-child(1) { grid-area: name; }
  .ship-card #orderTable td:nth-child(2) { grid-area: who; }
  .ship-card #orderTable td:nth-child(3) { grid-area: when; text-align: right; font-size: 12.5px; color: var(--text-3); }
  .ship-card #orderTable td:nth-child(4) { grid-area: price; text-align: right; font-weight: 750; }
  .ship-card #orderTable td:nth-child(5) { grid-area: addr; }
  .ship-card #orderTable td:nth-child(6) { grid-area: status; }
  .ship-card #orderTable td:nth-child(7) { grid-area: action; text-align: right; }
  .ship-card #orderTable td:nth-child(2)::before { content: "To "; color: var(--text-3); font-size: 12.5px; }

  /* Customers: name + button / address / counts */
  .ship-card #customerTable tr { grid-template-columns: auto auto minmax(0, 1fr) auto; grid-template-areas: "name name name action" "addr addr addr addr" "orders waiting last last"; }
  .ship-card #customerTable td:nth-child(1) { grid-area: name; }
  .ship-card #customerTable td:nth-child(2) { grid-area: addr; }
  .ship-card #customerTable td:nth-child(3) { grid-area: orders; }
  .ship-card #customerTable td:nth-child(4) { grid-area: waiting; }
  .ship-card #customerTable td:nth-child(5) { grid-area: last; text-align: right; }
  .ship-card #customerTable td:nth-child(6) { grid-area: action; text-align: right; }
  .ship-card #customerTable td:nth-child(n+3):nth-child(-n+5) { font-size: 12.5px; color: var(--text-2); }
  .ship-card #customerTable td:nth-child(3)::before { content: "Orders "; color: var(--text-3); }
  .ship-card #customerTable td:nth-child(4)::before { content: "To ship "; color: var(--text-3); }
  .ship-card #customerTable td:nth-child(5)::before { content: "Last "; color: var(--text-3); }
}

/* Dashboard and Resale tables on phones: each row becomes a card - the first column as its title,
   the rest as small labelled values three to a line, and any action button on its own line.
   (Shipping has its own layout above.) */
@media (max-width: 640px) {
  .card:not(.ship-card) .data-table thead { display: none; }
  .card:not(.ship-card) .data-table, .card:not(.ship-card) .data-table tbody { display: block; }
  .card:not(.ship-card) .table-wrap { overflow: visible; margin: 0; }
  .card:not(.ship-card) .data-table tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
  }
  .card:not(.ship-card) .data-table tr:last-child { border-bottom: none; }
  .card:not(.ship-card) .data-table tr:hover { background: none; }
  .card:not(.ship-card) .data-table td { display: block; padding: 0; border: 0; text-align: left; white-space: normal; min-width: 0; }
  .card:not(.ship-card) .data-table td:first-child { grid-column: 1 / -1; font-size: 14.5px; }
  .card:not(.ship-card) .data-table td:not(:first-child)[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-3);
  }
  /* Unlabelled columns hold buttons: give them a full-width line. */
  .card:not(.ship-card) .data-table td[data-label=""]:not(:first-child) { grid-column: 1 / -1; }
  .card:not(.ship-card) .data-table td[data-label=""] .btn { width: 100%; height: 38px; }
  .card:not(.ship-card) .share-cell { min-width: 0; }
  .card:not(.ship-card) .share-bar { display: block; width: 100%; margin: 0 0 4px; }
  .card:not(.ship-card) .more-btn { width: 100%; }
}
@media (max-width: 640px) {
  /* Empty "–" values just add height on a phone card. */
  .card:not(.ship-card) .data-table td.is-blank { display: none; }
}

/* ============================================================
   Chat (ask your data)
   ============================================================ */
.chat-model { display: inline-flex; align-items: center; gap: 8px; }
.chat-model select {
  height: 36px;
  max-width: 260px;
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  cursor: pointer;
}
.chat-model select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.chat-model select:disabled { opacity: 0.6; cursor: default; }

.chat-card { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: min(62vh, 640px);
  min-height: 320px;
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.chat-empty { margin: auto; text-align: center; color: var(--text-3); font-size: 13.5px; }
.chat-empty strong { display: block; margin-bottom: 12px; color: var(--text-2); font-size: 14px; }
.chat-suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 560px; }
.chat-suggestions button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.chat-suggestions button:hover { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }

.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble {
  max-width: min(78%, 680px);
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.chat-msg.user .chat-bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.chat-msg.assistant .chat-bubble { background: var(--surface-2); color: var(--text); border-bottom-left-radius: 6px; }
.chat-msg.error .chat-bubble { background: var(--owed-soft); color: var(--owed); font-weight: 600; }
.chat-bubble p + p, .chat-bubble p + ul, .chat-bubble p + ol, .chat-bubble ul + p, .chat-bubble ol + p { margin-top: 8px; }
.chat-bubble ul, .chat-bubble ol { padding-left: 20px; }
.chat-bubble code { padding: 1px 5px; border-radius: 6px; background: var(--surface-3); font-size: 0.9em; }
.chat-tool { align-self: flex-start; font-size: 12.5px; color: var(--text-3); font-style: italic; }

.chat-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.chat-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: chat-dot 1.2s infinite ease-in-out; }
.chat-typing i:nth-child(2) { animation-delay: 0.15s; }
.chat-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .chat-typing i { animation: none; opacity: 0.6; } }

.chat-form { display: flex; align-items: flex-end; gap: 10px; padding: 14px; border-top: 1px solid var(--border); }
.chat-form textarea { height: 44px; min-height: 44px; padding: 11px 14px; resize: none; line-height: 1.4; }
.chat-form .btn { width: 44px; height: 44px; padding: 0; flex-shrink: 0; }
.chat-form .btn.stop { background: var(--owed); box-shadow: none; color: #fff; }

@media (max-width: 640px) {
  .chat-log { height: 58vh; padding: 14px; }
  .chat-bubble { max-width: 88%; }
  .chat-model select { max-width: 180px; }
}
