/* Feel IT Insight — design system.
 * Mirrors feelit.pro landing palette: white + #f5f5f5 surfaces,
 * #1a5c38 primary green, Inter, green-tinted shadows.
 *
 * Layout breakpoints:
 *   <400px : narrow phone — extra-tight padding, smaller KPI values
 *   <760px : phone — bottom tab nav, hamburger drawer, KPI 2x2
 *   ≥760px : tablet — sidebar always visible, KPI 4x1
 *   ≥1100px: desktop — comfortable padding, charts side-by-side
 *
 * Notes on iPhone fit:
 *   - All grids use `minmax(0, 1fr)` so long currency strings can't push
 *     tracks wider than the viewport.
 *   - `body { overflow-x: hidden }` is a backstop, not the fix — content
 *     should fit by design.
 *   - 100dvh accounts for the dynamic URL bar; 100vh on iOS Safari can
 *     overflow under the bottom bar.
 *   - `env(safe-area-inset-*)` is honoured on main padding (landscape
 *     notch) and bottom-nav (home indicator).
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  /* feelit.pro palette */
  --green:        #1a5c38;
  --green-dark:   #144a2c;
  --green-soft:   #e8f3ed;
  --white:        #ffffff;
  --gray:         #f5f5f5;
  --gray-2:       #ececec;
  --gray-border:  #e2e2e2;
  --text:         #1a2a22;
  --muted:        #5a6a62;
  --muted-2:      #8a948f;

  /* Semantic */
  --positive:     #1a5c38;
  --negative:     #c0392b;
  --warning:      #d97706;

  /* Surfaces */
  --shadow-sm: 0 1px 2px rgba(20, 74, 44, .06), 0 1px 3px rgba(20, 74, 44, .04);
  --shadow-md: 0 4px 14px rgba(20, 74, 44, .08), 0 2px 4px rgba(20, 74, 44, .04);
  --shadow-lg: 0 14px 36px rgba(20, 74, 44, .12), 0 4px 10px rgba(20, 74, 44, .06);

  --radius:     14px;
  --radius-sm:   10px;
  --radius-lg:   20px;

  --sidebar-w:   220px;
  --topbar-h:    60px;
  --bottom-nav-h: 60px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; line-height: 1.5;
  color: var(--text); background: var(--gray);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-dark); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; }

/* ---- Splash (initial load) -------------------------------------------- */
.splash {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--gray);
}
.splash-inner {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}
.splash-spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(26, 92, 56, 0.18);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: splash-spin 0.75s linear infinite;
}
@keyframes splash-spin {
  to { transform: rotate(360deg); }
}
.splash-brand {
  font-size: 18px; font-weight: 700; letter-spacing: -0.02em;
  color: var(--muted);
}
.splash-brand span { color: var(--green); }

/* ---- Auth screens (login) --------------------------------------------- */
.auth-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, var(--green-soft) 0%, var(--white) 100%);
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--gray-border);
  padding: 32px 28px;
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 20px;
}
.auth-logo-img {
  height: 36px; width: auto; display: block;
}
.auth-logo .brand-suffix {
  font-weight: 600; font-size: 18px;
  color: var(--muted); letter-spacing: -0.01em;
}
.auth-logo .brand-name {
  font-size: 18px; font-weight: 800; letter-spacing: -0.01em;
}
.auth-card h1 { font-size: 24px; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.auth-card .form-row { margin-bottom: 14px; }
.auth-card label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--muted); margin-bottom: 6px; letter-spacing: .02em;
}
.auth-card input[type="email"],
.auth-card input[type="password"],
.auth-card input[type="text"] {
  width: 100%; min-height: 48px;
  padding: 12px 14px;
  font-size: 15px;
  border: 1.5px solid var(--gray-border);
  border-radius: 12px;
  background: var(--white); color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.auth-card input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(26, 92, 56, .12);
}
.auth-card .error {
  margin-top: 10px; padding: 10px 12px;
  background: rgba(192, 57, 43, .08); color: var(--negative);
  border-radius: 10px; font-size: 13px;
  display: none;
}
.auth-card .error.is-shown { display: block; }
.auth-card .hint { font-size: 12px; color: var(--muted-2); margin-top: 14px; text-align: center; }

/* ---- App shell -------------------------------------------------------- */
/* 100dvh accounts for the iOS Safari URL bar collapsing — 100vh would
 * push the bottom-nav under the chrome on first paint. Falls back to
 * 100vh in browsers that don't know about dvh. */
.app-shell { min-height: 100vh; min-height: 100dvh; display: flex; }

/* Sidebar (desktop ≥760px) / Drawer (mobile, slides in) */
.sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--gray-border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 30;
  flex-shrink: 0;
}
.sidebar-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--gray-border);
  display: flex; align-items: center; gap: 10px;
  min-height: var(--topbar-h);
}
.sidebar-logo { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sidebar-logo-img {
  /* Source SVG is 525×200; height-locked keeps it crisp at any sidebar width. */
  height: 26px; width: auto; display: block; flex-shrink: 0;
}
.brand-suffix {
  font-weight: 600; font-size: 14px;
  color: var(--muted);
  letter-spacing: -0.01em;
  white-space: nowrap;
}
/* Legacy classes kept for views that still reference them in fallback text */
.brand-text { font-weight: 800; font-size: 15px; letter-spacing: -0.01em; }
.brand-text .it-mark { color: var(--green); }
.sidebar-close {
  margin-left: auto; background: none; border: 0; padding: 6px;
  color: var(--muted); border-radius: 8px; display: none;
}
.sidebar-close:hover { background: var(--gray); color: var(--text); }

.nav {
  flex: 1; padding: 12px 10px; overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 2px;
  color: var(--muted); font-weight: 500; font-size: 14px;
  border-radius: var(--radius-sm);
  cursor: pointer; user-select: none;
}
.nav-item:hover { background: var(--gray); color: var(--text); }
.nav-item.is-active {
  background: var(--green-soft); color: var(--green); font-weight: 600;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-foot {
  padding: 12px 14px;
  border-top: 1px solid var(--gray-border);
  font-size: 12px;
}
.user-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--gray); margin-bottom: 8px;
  min-width: 0;
}
.user-pill .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--green); color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.user-pill .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-pill .who small { color: var(--muted); display: block; font-size: 11px; }

.lang-switch {
  display: block;
  margin-bottom: 8px;
}
.lang-select {
  width: 100%;
  font-size: 12px; font-weight: 600;
  padding: 7px 9px; border-radius: 8px;
  border: 1px solid var(--gray-border);
  background: var(--gray); color: var(--text);
  letter-spacing: .03em; cursor: pointer;
}
.lang-select:hover { border-color: var(--green); }
.lang-select:focus { outline: none; border-color: var(--green); }

.logout-link {
  display: block; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: 13px; font-weight: 500;
}
.logout-link:hover { background: var(--gray); color: var(--negative); }

/* ---- Body / topbar / content ----------------------------------------- */
.app-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  /* Reserve room for bottom tabs on mobile so the last row of content
     isn't hidden behind the fixed nav. */
  padding-bottom: 0;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--gray-border);
  min-height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 8px 18px;
}
.topbar-toggle {
  background: none; border: 0; padding: 6px;
  color: var(--text); border-radius: 8px;
  display: none; /* shown on phone */
}
.topbar-toggle svg { width: 22px; height: 22px; }
.topbar-toggle:hover { background: var(--gray); }

/* Help button — global ? icon. Same shape as topbar-toggle so it lines up
 * visually. Shown on every screen size; on phone its label collapses
 * naturally because it's icon-only. */
.topbar-help {
  background: none; border: 0; padding: 6px;
  color: var(--muted); border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.topbar-help svg { width: 20px; height: 20px; }
.topbar-help:hover { background: var(--gray); color: var(--green); }
.topbar .biz-name {
  font-weight: 700; font-size: 15px;
  flex-shrink: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 200px;
}
.topbar .spacer { flex: 1; }

/* Date range picker pill */
.daterange {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--gray); padding: 6px 12px; border-radius: 100px;
  font-size: 13px; color: var(--text);
  border: 1px solid transparent;
  cursor: pointer; user-select: none;
}
.daterange:hover { border-color: var(--gray-border); }
.daterange svg { width: 14px; height: 14px; color: var(--muted); }
.daterange .label { font-weight: 500; }

/* Sync status */
.sync-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 100px;
  background: var(--green-soft); color: var(--green);
  font-size: 12px; font-weight: 600;
  border: 0; cursor: pointer; user-select: none;
}
.sync-pill .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--green);
}
.sync-pill.is-running .dot { animation: pulse 1.4s ease-in-out infinite; }
.sync-pill.is-stale { background: rgba(217, 119, 6, .12); color: var(--warning); }
.sync-pill.is-stale .dot { background: var(--warning); }
.sync-pill.is-error { background: rgba(192, 57, 43, .08); color: var(--negative); }
.sync-pill.is-error .dot { background: var(--negative); }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .55; transform: scale(1.4); }
}

/* Main content */
.main {
  flex: 1; min-width: 0; padding: 18px;
}
.view-title {
  font-size: 22px; font-weight: 700; margin: 0 0 4px;
}
.view-sub {
  color: var(--muted); font-size: 13px; margin: 0 0 18px;
}

/* ---- Cards ------------------------------------------------------------ */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-border);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-head h3 { font-size: 14px; color: var(--text); font-weight: 600; }
.card-head .head-action {
  font-size: 12px; color: var(--muted); font-weight: 500;
  display: inline-flex; align-items: center; gap: 4px;
}
.card-head .badge-muted {
  background: var(--gray); color: var(--muted);
  padding: 3px 8px; border-radius: 100px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}

/* ---- KPI tiles ------------------------------------------------------- */
.kpi-grid {
  display: grid; gap: 12px;
  /* minmax(0, 1fr) instead of 1fr — without the explicit 0 minimum a long
   * formatted currency string ("1 234 567,00 €") can force a track wider
   * than the viewport and push the whole page sideways on narrow phones. */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
}
.kpi {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-border);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px;
  min-width: 0;
}
.kpi .label {
  font-size: 11px; font-weight: 600; color: var(--muted);
  letter-spacing: .04em; text-transform: uppercase;
  display: flex; align-items: center; gap: 4px;
}
.kpi .label svg { width: 14px; height: 14px; color: var(--muted-2); }
.kpi .value {
  font-size: 24px; font-weight: 800; color: var(--text);
  letter-spacing: -0.02em; line-height: 1.1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi .delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
  color: var(--muted);
}
.kpi .delta.positive { color: var(--positive); }
.kpi .delta.negative { color: var(--negative); }
.kpi .delta svg { width: 12px; height: 12px; }
.kpi .sub { font-size: 11px; color: var(--muted-2); margin-top: 2px; }

/* ---- Charts row ------------------------------------------------------ */
.row {
  display: grid; gap: 12px;
  grid-template-columns: minmax(0, 1fr);
  margin-bottom: 18px;
}
.row-2 { grid-template-columns: minmax(0, 1fr); }
.chart-card { min-height: 280px; }
.chart-wrap {
  /* Fixed 220px height keeps Chart.js bars readable on phones. The wrap
   * is the canvas's positioning parent — Chart.js needs an explicit height
   * here, it won't compute one from content. */
  position: relative; height: 220px; width: 100%;
}

/* ---- ABC analysis --------------------------------------------------- */
.abc-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 18px;
  padding: 14px 16px; margin-bottom: 18px;
}
.abc-ctl-group { display: inline-flex; align-items: center; gap: 8px; }
.abc-ctl-label { font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.abc-seg { display: inline-flex; background: var(--gray); border-radius: 8px; padding: 3px; gap: 2px; }
.abc-seg-btn {
  border: 0; background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 6px;
}
.abc-seg-btn.is-active { background: var(--white); color: var(--green); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.abc-th-input {
  width: 56px; padding: 6px 8px; border: 1px solid var(--gray-border);
  border-radius: 6px; font-size: 13px; text-align: right;
}
.abc-th-suffix { font-size: 13px; color: var(--muted-2); margin-left: -4px; }
.abc-th-note { font-size: 12px; color: var(--muted-2); font-style: italic; }
.abc-class-card .label { display: flex; align-items: center; gap: 4px; }
.abc-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 5px;
  color: #fff; font-size: 11px; font-weight: 800;
}
.abc-pareto { position: relative; height: 340px; width: 100%; }
.abc-filter { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.abc-chip {
  border: 1px solid var(--gray-border); background: var(--white); color: var(--muted);
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 20px;
}
.abc-chip.is-active { background: var(--green); border-color: var(--green); color: #fff; }
.abc-cap-note { font-size: 12px; color: var(--muted-2); padding: 10px 4px 2px; text-align: center; }
@media (max-width: 759px) {
  .abc-controls { gap: 12px; }
  .abc-pareto { height: 260px; }
}

/* ---- Report card controls (sort/category/granularity) --------------- */
.report-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}
.report-control {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
}
.report-control-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}
.report-control select {
  border: 1px solid var(--gray-border);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--white);
  color: var(--text);
  font-size: 13px;
  min-width: 130px;
  cursor: pointer;
}
.report-control select:focus {
  outline: 2px solid var(--green-soft);
  border-color: var(--green);
}

/* ---- Card head subtitle (period + total badge) ----------------------- */
.range-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.range-badge .rb-sep { color: var(--gray-border); }
.range-badge .rb-total strong {
  color: var(--text);
  font-weight: 700;
  margin-left: 2px;
}
@media (max-width: 759px) {
  .range-badge { font-size: 11px; gap: 4px; }
  .range-badge .rb-total { display: inline-flex; }
}

/* ---- By-category donut card (Inventory) ----------------------------- */
.cat-pane {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 18px;
  align-items: center;
}
.cat-chart {
  position: relative;
  height: 220px;
  min-width: 0;
}
.cat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  font-size: 13px;
}
.cat-row {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--gray-border);
}
.cat-row:last-child { border-bottom: 0; }
.cat-row .swatch {
  width: 12px; height: 12px; border-radius: 3px;
}
.cat-row .name {
  color: var(--text);
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cat-row .pct {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.cat-row .val {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 759px) {
  .cat-pane {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .cat-chart { height: 180px; }
}

/* ---- Alerts modal (bell button content) ----------------------------- */
/* Wider than default modal — alerts content has descriptions + samples per
 * category and looked cramped at 460px. :has() targets the parent modal
 * only when our content is inside it (Chrome 105+, Safari 15.4+, FF 121+). */
.modal:has(.alerts-modal) { max-width: 580px; }
.alerts-modal { display: flex; flex-direction: column; gap: 14px; }
.alerts-intro {
  color: var(--muted); font-size: 13px; margin: 0 0 4px;
  line-height: 1.5;
}
.alerts-section {
  border: 1px solid var(--gray-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--white);
}
.alerts-section-head {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-border);
  margin-bottom: 8px;
}
.alerts-section-head.is-clickable {
  cursor: pointer;
  margin: -12px -14px 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-border);
  transition: background .15s;
}
.alerts-section-head.is-clickable:hover { background: var(--gray); }
.alerts-section-head .alerts-icon {
  font-size: 18px; flex-shrink: 0;
}
.alerts-section-head .alerts-title {
  flex: 1; min-width: 0;
  font-size: 14px; font-weight: 700; color: var(--text); margin: 0;
}
.alerts-section-head .alerts-count {
  background: #c0392b; color: #fff;
  padding: 2px 8px; border-radius: 100px;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.alerts-desc {
  font-size: 12px; color: var(--muted);
  margin: 0 0 8px; line-height: 1.5;
}
.alerts-sample { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.alerts-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 4px 0;
}
.alerts-name {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.alerts-value {
  color: var(--text); font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.alerts-more {
  font-size: 11px; color: var(--muted); font-style: italic;
  padding-top: 6px;
}

/* ---- Topbar alerts badge --------------------------------------------- */
.topbar-alerts {
  position: relative;
  background: transparent;
  border: 1px solid var(--gray-border);
  border-radius: 100px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text);
  display: inline-flex;
  align-items: center;
}
.topbar-alerts:hover { background: var(--gray); }
.topbar-alerts .alerts-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 100px;
  background: #c0392b;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.topbar-alerts .alerts-badge.zero { display: none; }

/* ---- Tables ---------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;     /* smooth momentum scroll on iOS */
  margin: -6px;
  padding: 6px;
}
/* Thin scrollbar so it's visible but doesn't eat into the card padding. */
.table-wrap::-webkit-scrollbar { height: 6px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--gray-border); border-radius: 4px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.table th, .table td {
  text-align: left; padding: 10px 8px;
  border-bottom: 1px solid var(--gray-border);
}
.table th {
  font-weight: 600; color: var(--muted);
  font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
  background: transparent;
}
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .muted { color: var(--muted); font-size: 12px; }

/* Recent / list rows on mobile become card-like */
.list-rows .list-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-border);
  display: grid; grid-template-columns: 1fr auto; gap: 4px;
  align-items: baseline;
}
.list-rows .list-row:last-child { border-bottom: 0; }
.list-rows .list-row .primary { font-weight: 600; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list-rows .list-row .secondary { color: var(--muted); font-size: 12px; }
.list-rows .list-row .amount { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }

/* ---- Top-products horizontal bars ----------------------------------- */
.hbar-list { display: flex; flex-direction: column; gap: 10px; }
.hbar {
  display: grid; grid-template-columns: 1fr auto; gap: 4px;
  align-items: baseline; font-size: 13px;
}
.hbar .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.hbar .val { font-variant-numeric: tabular-nums; font-weight: 600; }
.hbar .track {
  grid-column: 1 / -1;
  height: 6px; background: var(--gray); border-radius: 100px; overflow: hidden;
}
.hbar .track .fill {
  height: 100%; background: var(--green); border-radius: 100px;
  transition: width .5s cubic-bezier(.2,.8,.2,1);
}

/* ---- Badges --------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700;
  padding: 4px 9px; border-radius: 100px;
  letter-spacing: .04em; text-transform: uppercase;
  line-height: 1;
}
.badge-positive { background: var(--green-soft); color: var(--green); }
.badge-warning  { background: rgba(217, 119, 6, .12); color: var(--warning); }
.badge-danger   { background: rgba(192, 57, 43, .1); color: var(--negative); }
.badge-muted    { background: var(--gray); color: var(--muted); }

/* ---- Buttons -------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; min-height: 44px;
  font-size: 14px; font-weight: 600;
  border-radius: 12px; border: 0; cursor: pointer;
  line-height: 1.2;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease, color .15s ease;
}
.btn-primary { background: var(--green); color: var(--white); }
.btn-primary:hover { background: var(--green-dark); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: transparent; color: var(--green); border: 1.5px solid var(--green); }
.btn-ghost:hover { background: var(--green-soft); }
.btn-subtle { background: var(--gray); color: var(--text); }
.btn-subtle:hover { background: var(--gray-2); }
.btn-danger { background: var(--negative); color: var(--white); }
.btn-sm { padding: 7px 12px; min-height: 32px; font-size: 12px; border-radius: 9px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

/* ---- Forms --------------------------------------------------------- */
.form-row { margin-bottom: 12px; }
.form-row label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--muted); margin-bottom: 5px; letter-spacing: .02em;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], select, textarea {
  width: 100%; min-height: 40px;
  padding: 9px 12px;
  font-size: 14px;
  border: 1.5px solid var(--gray-border);
  border-radius: 10px;
  background: var(--white); color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(26, 92, 56, .12);
}

/* ---- Mixed currency banner ------------------------------------------ */
.banner {
  padding: 12px 14px; border-radius: var(--radius);
  background: rgba(217, 119, 6, .08); color: var(--warning);
  border: 1px solid rgba(217, 119, 6, .25);
  font-size: 13px; margin-bottom: 14px;
  display: flex; align-items: flex-start; gap: 10px;
}
.banner svg { flex-shrink: 0; margin-top: 2px; }
.banner select {
  margin-left: 8px; padding: 4px 8px; min-height: 28px;
  background: var(--white); border-color: rgba(217, 119, 6, .35);
}

/* ---- Help modal sections -------------------------------------------- */
/* Rendered inside UI.modal({ body }) — one section per block of the
 * current view, h4 + p pair, modest separators. */
.help-list {
  display: flex; flex-direction: column; gap: 14px;
  font-size: 13px; line-height: 1.55;
}
.help-list .help-section {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-border);
}
.help-list .help-section:last-child { border-bottom: 0; padding-bottom: 0; }
.help-list h4 {
  font-size: 13px; font-weight: 700; color: var(--green);
  margin: 0 0 4px;
}
.help-list p { margin: 0; color: var(--text); }

/* ---- Empty states --------------------------------------------------- */
.empty {
  padding: 30px 18px; text-align: center;
  color: var(--muted); font-size: 13px;
}
.empty .empty-title { font-weight: 600; color: var(--text); margin-bottom: 4px; }

/* ---- Sync status block (Settings → Sources cards) ------------------- */
/* Visible-at-a-glance state of the integration's sync: idle/running/ok/error.
 * Sits where the old "Last sync: X ago" line was. Replaces in-place every
 * 5–30s — no card rebuild, so action buttons keep state. */
.sync-status {
  display: flex; flex-direction: column; gap: 6px;
  padding: 9px 12px; border-radius: 10px;
  background: var(--gray); color: var(--text);
  font-size: 12.5px; font-weight: 600;
  margin-bottom: 12px;
  border: 1px solid transparent;
}
.sync-status.is-running { background: var(--green-soft); color: var(--green-dark); border-color: rgba(26, 92, 56, .12); }
.sync-status.is-ok      { background: var(--green-soft); color: var(--green-dark); }
.sync-status.is-error   { background: rgba(192, 57, 43, .08); color: var(--negative); border-color: rgba(192, 57, 43, .18); }
.sync-status.is-never   { color: var(--muted); }
.sync-line  { display: flex; align-items: center; gap: 8px; }
.sync-icon  { display: inline-flex; width: 18px; justify-content: center; font-size: 14px; }
.sync-text  { flex: 1; }
.sync-spin  { animation: sync-spin 1.4s linear infinite; transform-origin: 50% 50%; }
@keyframes sync-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.sync-ok-icon  { color: var(--green); }
.sync-err-icon { color: var(--negative); }
.sync-err-msg  {
  font-size: 11.5px; font-weight: 500;
  color: var(--negative); opacity: .9;
  background: rgba(192, 57, 43, .05);
  padding: 6px 9px; border-radius: 7px;
  word-break: break-word;
}
.sync-warn {
  font-size: 11.5px; font-weight: 500;
  color: var(--warning, #d97706);
  background: rgba(217, 119, 6, .1);
  padding: 5px 9px; border-radius: 7px;
}
/* Indeterminate progress bar — a 30%-wide chunk sliding right→left→right.
 * No real progress info from backend yet (sync phases aren't streamed mid-run),
 * but the animation reassures the user the process is alive. */
.sync-bar {
  position: relative; height: 4px; border-radius: 100px;
  background: rgba(26, 92, 56, .15); overflow: hidden;
}
.sync-bar-fill {
  position: absolute; top: 0; bottom: 0; width: 30%;
  background: var(--green);
  border-radius: 100px;
  animation: sync-slide 1.7s cubic-bezier(.4, 0, .2, 1) infinite;
}
@keyframes sync-slide {
  0%   { left: -30%; }
  60%  { left: 100%; }
  100% { left: 100%; }
}
/* Reduced motion — leave a static partial fill so the bar still communicates
 * "running" without an animation. */
@media (prefers-reduced-motion: reduce) {
  .sync-spin     { animation: none; }
  .sync-bar-fill { animation: none; left: 0; width: 50%; opacity: .6; }
}

/* ---- Logs tab (Settings → Logs) ------------------------------------- */
/* Compact one-row-per-sync browser with inline expansion. Each row is a
 * clickable strip: timestamp · mode · status badge · duration · records.
 * Click toggles the detail block (phase timings + counts + full error). */
.log-filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.log-filter-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.log-filter-label {
  font-size: 11px; font-weight: 700; color: var(--muted-2);
  text-transform: uppercase; letter-spacing: .05em;
  margin-right: 4px;
}
.log-chip {
  padding: 5px 11px; border-radius: 100px; border: 1px solid var(--gray-border);
  background: var(--white); color: var(--text);
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.log-chip:hover { background: var(--gray); }
.log-chip.is-active { background: var(--green); color: var(--white); border-color: var(--green); }

.log-list { display: flex; flex-direction: column; gap: 4px; }
.log-row {
  background: var(--white);
  border: 1px solid var(--gray-border);
  border-radius: 9px;
  overflow: hidden;
}
.log-row-error  { border-color: rgba(192, 57, 43, .25); }
.log-row-running { border-color: rgba(26, 92, 56, .25); }
.log-head {
  display: grid;
  grid-template-columns: 96px minmax(60px, auto) minmax(72px, auto) 1fr auto 22px;
  align-items: center; gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  font-size: 12.5px;
}
.log-head:hover { background: var(--gray); }
.log-time { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
.log-mode { font-weight: 700; color: var(--text); }
.log-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 100px;
  font-size: 10.5px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
}
.log-badge-ok      { background: var(--green-soft); color: var(--green); }
.log-badge-error   { background: rgba(192, 57, 43, .12); color: var(--negative); }
.log-badge-running { background: rgba(26, 92, 56, .12); color: var(--green-dark); }
.log-dur { color: var(--muted); font-variant-numeric: tabular-nums; }
.log-recs { color: var(--muted-2); font-size: 11.5px; text-align: right; }
.log-toggle {
  background: transparent; border: 0;
  color: var(--muted-2); font-size: 14px; cursor: pointer;
  padding: 0; width: 22px; height: 22px;
}

.log-detail { padding: 0 12px; }
.log-detail:empty { padding: 0; }
.log-detail > div:not(:empty) { padding-bottom: 12px; padding-top: 4px; border-top: 1px dashed var(--gray-2); }
.log-detail-section-title {
  font-size: 10.5px; font-weight: 700; color: var(--muted-2);
  text-transform: uppercase; letter-spacing: .06em;
  margin: 10px 0 6px 0;
}
.log-err-title { color: var(--negative); }
.log-phase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 4px 14px;
}
.log-phase {
  display: flex; justify-content: space-between;
  font-size: 12px; padding: 3px 0;
}
.log-phase-name { color: var(--muted); }
.log-phase-val  { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.log-err {
  white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px; line-height: 1.45;
  background: rgba(192, 57, 43, .05);
  color: var(--negative);
  padding: 9px 11px; border-radius: 7px;
  margin: 0;
  max-height: 240px; overflow: auto;
}
.log-no-detail {
  color: var(--muted-2); font-size: 12px; font-style: italic;
  padding: 6px 0;
}
.log-foot {
  margin-top: 12px;
  font-size: 11.5px; color: var(--muted-2);
  text-align: right;
}

/* Mobile: stack header columns since the grid gets cramped under 480px.
 * Time stays first; mode/badge/dur fall under it. Records hidden — info
 * surfaces in the detail block on tap. */
@media (max-width: 480px) {
  .log-head {
    grid-template-columns: 1fr auto 22px;
    grid-template-areas:
      "time  badge toggle"
      "mode  dur   ."
      "recs  recs  .";
    row-gap: 4px;
  }
  .log-time   { grid-area: time; }
  .log-mode   { grid-area: mode; font-size: 11.5px; }
  .log-badge  { grid-area: badge; justify-self: end; }
  .log-dur    { grid-area: dur; text-align: right; }
  .log-recs   { grid-area: recs; text-align: left; }
  .log-toggle { grid-area: toggle; }
}

/* ---- Toast --------------------------------------------------------- */
#toast-root {
  position: fixed; bottom: calc(var(--bottom-nav-h) + 20px); left: 50%;
  transform: translateX(-50%); z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  max-width: calc(100vw - 32px);
}
.toast {
  background: var(--text); color: var(--white);
  padding: 10px 16px; border-radius: 100px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in .25s ease;
}
.toast.is-error { background: var(--negative); }
.toast.is-success { background: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Modal --------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(20, 30, 24, .55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade-in .2s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--white); border-radius: var(--radius-lg);
  width: 100%; max-width: 460px;
  max-height: calc(100vh - 32px); overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  padding: 18px 22px 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h2 { font-size: 18px; }
.modal-close {
  background: none; border: 0; padding: 4px; color: var(--muted);
  border-radius: 8px;
}
.modal-close:hover { background: var(--gray); color: var(--text); }
.modal-body { padding: 8px 22px 18px; }
.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--gray-border);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* ---- Bottom nav (phone only) --------------------------------------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--white);
  border-top: 1px solid var(--gray-border);
  display: none; /* shown on phone */
  z-index: 25;
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  padding: 6px 4px;
  color: var(--muted); font-size: 10px; font-weight: 600;
  cursor: pointer; user-select: none;
}
.bottom-nav-item svg { width: 20px; height: 20px; }
.bottom-nav-item.is-active { color: var(--green); }
.bottom-nav-item.is-active svg { color: var(--green); }

/* Backdrop for sidebar drawer on mobile */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 28;
  background: rgba(20, 30, 24, .4);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  animation: fade-in .15s ease;
}

/* ============================================================
   Mobile-first → larger screens
   ============================================================ */

/* ---- Phone (default <760) ---- */
@media (max-width: 759px) {
  .sidebar {
    position: fixed; top: 0; left: 0;
    height: 100vh; height: 100dvh; width: 270px;
    transform: translateX(-100%);
    transition: transform .22s cubic-bezier(.2,.8,.2,1);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop.is-open { display: block; }
  .sidebar-close { display: inline-flex; }
  .topbar-toggle { display: inline-flex; }
  .bottom-nav { display: flex; }
  .app-body { padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom)); }
  /* Main padding respects horizontal safe area for landscape with notch. */
  .main {
    padding: 14px;
    padding-left:  max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .topbar {
    padding: 8px 12px; gap: 6px;
    padding-left:  max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .topbar .biz-name { font-size: 14px; max-width: 130px; min-width: 0; }
  .daterange { padding: 6px 10px; }
  .daterange .label { display: none; }
  .sync-pill { padding: 6px 10px; }
  .sync-pill .label { display: none; }

  /* View headers shrink — 22px h1 burns vertical room above-the-fold */
  .view-title { font-size: 18px; }
  .view-sub { font-size: 12px; margin-bottom: 14px; }

  /* KPI tiles — value text was 24px which can clip a 9-digit currency
   * value on a 390px screen split 2-up. 18px keeps the symbol + number
   * intact for sums up to a million euro. */
  .kpi { padding: 12px 14px; gap: 2px; }
  .kpi .label { font-size: 10px; }
  .kpi .value { font-size: 18px; letter-spacing: -0.01em; }
  .kpi .delta { font-size: 11px; flex-wrap: wrap; }

  /* Card padding tightened to give content more breathing room */
  .card { padding: 14px; }
  .card-head { margin-bottom: 10px; }

  /* Chart card minimum lowered — the 280px floor was wasting vertical
   * space on small chart series. */
  .chart-card { min-height: auto; }
  .chart-wrap { height: 200px; }

  /* Tables on mobile: force the table to its NATURAL content width so the
   * wrap's overflow-x:auto actually scrolls. With width:100%, the browser
   * forces the table to fit the card; columns then squash and content
   * disappears even with nowrap. width:max-content lets columns size to
   * their content; min-width:100% fills short tables to card edge.
   * (Sticky-first-column was tried but broke swipe — touch on the pinned
   * cell didn't propagate horizontal scroll. Removed.) */
  .table { width: max-content; min-width: 100%; }
  .table th, .table td { white-space: nowrap; }
  .table .truncate { max-width: none; overflow: visible; }
}

/* ---- Extra-narrow phones (iPhone mini / SE / portrait < 400px) ---- */
@media (max-width: 399px) {
  .main { padding: 10px; }
  .kpi-grid { gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .value { font-size: 16px; }
  .kpi .label { font-size: 9px; letter-spacing: .03em; }
  .topbar .biz-name { max-width: 100px; font-size: 13px; }
  .topbar { gap: 4px; }
  .card { padding: 12px; }
  .chart-wrap { height: 180px; }
  .view-title { font-size: 17px; }
}

/* ---- Tablet+ (≥760) ---- */
@media (min-width: 760px) {
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .row-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .main { padding: 22px 26px; }
  .kpi .value { font-size: 26px; }
}

/* ---- Desktop (≥1100) ---- */
@media (min-width: 1100px) {
  .main { padding: 26px 32px; max-width: 1400px; }
}

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