/* ============================================================
   Artico Sales App — Mobile-first stylesheet
   Primary device: iPhone (375px+)
   ============================================================ */

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Brand palette */
  --color-primary:    #1B3A6B;   /* Artico navy */
  --color-accent:     #E8501A;   /* Artico orange */
  --color-success:    #3DAA6E;
  --color-warning:    #F0B429;
  --color-danger:     #D94F4F;

  /* Neutrals */
  --color-bg:         #F5F6FA;
  --color-surface:    #FFFFFF;
  --color-border:     #E0E3EC;
  --color-text:       #1A1D2E;
  --color-muted:      #6B7280;

  /* Grade colours */
  --grade-a:          #3DAA6E;
  --grade-b:          #F0B429;
  --grade-c:          #D94F4F;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  /* Typography */
  --font-base: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
}

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

body {
  font-family: var(--font-base);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  min-height: 100dvh;
}

/* ── Layout ── */
.container {
  width: 100%;
  max-width: 480px;  /* comfortable phone width */
  margin: 0 auto;
  padding: 0 var(--space-4);
}

/* Wider for tablet/desktop sidebars */
@media (min-width: 768px) {
  .container { max-width: 960px; }
}

/* ── Top navigation bar ── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-md);
}

.navbar__brand { font-size: var(--text-lg); font-weight: 700; letter-spacing: -0.02em; }
.navbar__user  { font-size: var(--text-sm); opacity: 0.85; }

/* ── Cards ── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.card__title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}

.card__value {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-text);
}

/* ── Stat grid (2-up on phone) ── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

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

/* ── Grade badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  font-size: var(--text-sm);
  font-weight: 700;
  color: #fff;
}

.badge--a { background: var(--grade-a); }
.badge--b { background: var(--grade-b); }
.badge--c { background: var(--grade-c); }

/* ── Progress bar ── */
.progress { background: var(--color-border); border-radius: 99px; height: 8px; overflow: hidden; }
.progress__fill { height: 100%; border-radius: 99px; background: var(--color-primary); transition: width 0.4s ease; }
.progress__fill--danger  { background: var(--color-danger); }
.progress__fill--warning { background: var(--color-warning); }
.progress__fill--success { background: var(--color-success); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-sm);
  border: none;
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

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

.btn--primary   { background: var(--color-primary); color: #fff; }
.btn--accent    { background: var(--color-accent);  color: #fff; }
.btn--ghost     { background: transparent; color: var(--color-primary); border: 1.5px solid var(--color-primary); }
.btn--danger    { background: var(--color-danger);  color: #fff; }
.btn--full      { width: 100%; }

/* ── Form elements ── */
.form-group { margin-bottom: var(--space-4); }
.form-label { display: block; font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--space-1); }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-3);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-family: var(--font-base);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(44,95,138,0.15);
}

.form-textarea { resize: vertical; min-height: 80px; }

/* ── Alert chips ── */
.alert-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

.alert-chip--warning { background: #FEF3C7; color: #92400E; }
.alert-chip--danger  { background: #FEE2E2; color: #991B1B; }
.alert-chip--info    { background: #DBEAFE; color: #1E40AF; }

/* ── Bottom tab bar (mobile nav) ── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-bar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-2) 0;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--color-muted);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.tab-bar__item.active,
.tab-bar__item:hover { color: var(--color-primary); }

.tab-bar__icon { font-size: 1.3rem; }

/* Push content above tab bar */
.has-tab-bar { padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0)); }

/* ── Dashboard — Hero card ── */
.dash-hero { padding: var(--space-5, 1.25rem) var(--space-4); }
.dash-hero__label  { font-size: var(--text-sm); font-weight: 600; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: var(--space-1); }
.dash-hero__actual { font-size: 2.25rem; font-weight: 800; color: var(--color-text); line-height: 1.1; }
.dash-hero__target { font-size: var(--text-sm); margin-bottom: var(--space-3); }
.dash-hero__meta   { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-3); flex-wrap: wrap; }

.pct-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: var(--text-sm);
  font-weight: 700;
}
.pct-badge--success { background: #D1FAE5; color: #065F46; }
.pct-badge--warning { background: #FEF3C7; color: #92400E; }
.pct-badge--danger  { background: #FEE2E2; color: #991B1B; }
.pct-badge--muted   { background: var(--color-border); color: var(--color-muted); }

/* ── Dashboard — stat numbers ── */
.stat-num { font-size: var(--text-2xl); font-weight: 700; color: var(--color-text); }
.stat-lbl { font-size: var(--text-sm); color: var(--color-muted); margin-top: 2px; }
.stat-grid--2 { grid-template-columns: 1fr 1fr !important; }
.stat-grid--3 { grid-template-columns: repeat(3, 1fr) !important; }

/* ── Dashboard — quick stat mini cards ── */
.stat-mini          { text-align: center; padding: var(--space-3) var(--space-2); }
.stat-mini__val     { font-size: var(--text-xl); font-weight: 800; color: var(--color-text); }
.stat-mini__lbl     { font-size: 0.7rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.stat-mini--alert   { border: 1.5px solid var(--color-warning); }
.stat-mini--alert .stat-mini__val { color: var(--color-warning); }

/* ── Dashboard — Chart.js wrapper ── */
.chart-wrap { position: relative; height: 160px; }

/* ── Dashboard — Brand breakdown ── */
.brand-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}
.brand-row__name    { width: 110px; flex-shrink: 0; color: var(--color-text); font-weight: 500; }
.brand-row__bar-wrap{ flex: 1; background: var(--color-border); border-radius: 99px; height: 8px; overflow: hidden; }
.brand-row__bar     { height: 100%; background: var(--color-primary); border-radius: 99px; transition: width 0.4s ease; }
.brand-row__meta    { display: flex; flex-direction: column; align-items: flex-end; width: 70px; flex-shrink: 0; }

/* ── Dashboard — Freshness banner ── */
.freshness-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-muted);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  margin: 0 calc(-1 * var(--space-4));
  flex-wrap: wrap;
}
.freshness-bar--stale { background: #FEF3C7; color: #92400E; border-color: #F0B429; }
.freshness-warn { font-weight: 600; }
.btn-text {
  background: none; border: none; color: var(--color-primary); font-size: var(--text-sm);
  cursor: pointer; padding: 0; margin-left: auto; font-weight: 600; text-decoration: underline;
}
.btn-icon-sm {
  background: none; border: 1px solid var(--color-border); border-radius: 6px;
  padding: 4px 8px; font-size: 1rem; cursor: pointer; color: var(--color-muted);
  -webkit-tap-highlight-color: transparent;
}
.btn-icon-sm:hover { color: var(--color-primary); }

/* ── Dashboard — Pull-to-refresh indicator ── */
.pull-indicator {
  position: sticky;
  top: 0;
  z-index: 40;
  text-align: center;
  padding: var(--space-2);
  font-size: var(--text-sm);
  background: var(--color-primary);
  color: #fff;
}

/* ── Team dashboard — Leaderboard ── */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.leader-list { padding: var(--space-2) 0; }

.leader-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
}

.leader-row--total {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-3);
  margin-top: var(--space-1);
}

.leader-row__rank   { width: 20px; text-align: right; font-size: var(--text-sm); flex-shrink: 0; }
.leader-row__info   { flex: 1; min-width: 0; }
.leader-row__name   { font-size: var(--text-sm); font-weight: 600; margin-bottom: 4px; }
.leader-row__bar    { }
.leader-row__nums   { text-align: right; flex-shrink: 0; }
.leader-row__actual { font-size: var(--text-sm); font-weight: 700; }
.leader-row__pct    { font-size: var(--text-sm); font-weight: 600; }
.leader-row__terr   { line-height: 1.2; }

/* ── Territory Growth card ── */
.tg-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.tg-cell { text-align: center; flex: 1; }
.tg-badge-wrap { flex-shrink: 0; }
.tg-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 99px;
  font-size: var(--text-lg);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.tg-badge--success { background: #D1FAE5; color: #065F46; }
.tg-badge--danger  { background: #FEE2E2; color: #991B1B; }
.tg-badge--muted   { background: var(--color-border); color: var(--color-muted); }

/* ── Team dashboard — Brand table ── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.brand-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.brand-table th {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.brand-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.brand-table tbody tr:last-child td { border-bottom: none; }
.brand-td__name { font-weight: 600; }

/* ── Team dashboard — New doors ── */
.door-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-sm);
}
.door-row:last-child { border-bottom: none; }

/* ── Screen system ── */
.screen { display: flex; flex-direction: column; min-height: 100dvh; }
.screen.hidden { display: none !important; }

/* ── Auth screens ── */
.auth-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-4);
  min-height: 100dvh;
  background: var(--color-bg);
}

.auth-logo {
  text-align: center;
  margin-bottom: var(--space-8);
}

.auth-logo__mark {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-lg);
  background: var(--color-primary);
  color: #fff;
  font-size: 2rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-3);
}

.auth-logo__name {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
}

.auth-logo__sub {
  font-size: var(--text-sm);
  color: var(--color-muted);
  margin-top: var(--space-1);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-6);
}

.auth-card__title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: var(--space-2);
}

.auth-card__desc {
  font-size: var(--text-sm);
  color: var(--color-muted);
  margin-bottom: var(--space-4);
}

.form-error {
  color: var(--color-danger);
  font-size: var(--text-sm);
  margin-bottom: var(--space-3);
}

.form-hint {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--color-muted);
  margin-top: 2px;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  padding-top: calc(var(--space-3) + env(safe-area-inset-top, 0));
  box-shadow: var(--shadow-md);
}

.app-header__brand {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-header__right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.app-header__user {
  font-size: var(--text-sm);
  opacity: 0.85;
}

.app-header__logout {
  background: transparent;
  border: none;
  color: #fff;
  opacity: 0.75;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.app-header__logout:hover { opacity: 1; }

/* ── Main content ── */
.app-main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-4);
  padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0));
}

.page { display: block; }
.page.hidden { display: none !important; }

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.page-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--color-muted);
}

.section-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}

/* ── Skeleton loading blocks ── */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

.skeleton-block {
  height: 80px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg,
    var(--color-border) 25%,
    #f0f1f5 50%,
    var(--color-border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  margin-bottom: var(--space-3);
}

.skeleton-block--sm { height: 48px; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--color-muted);
}

.empty-state__icon { font-size: 2.5rem; margin-bottom: var(--space-3); }
.empty-state__title { font-size: var(--text-lg); font-weight: 600; margin-bottom: var(--space-2); color: var(--color-text); }
.empty-state__desc  { font-size: var(--text-sm); }

/* ── Tab bar (button-based) ── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-bar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-2) 0;
  min-height: 52px;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--color-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.tab-bar__item.active { color: var(--color-primary); }
.tab-bar__item:hover  { color: var(--color-primary); }

.tab-icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(4.5rem + env(safe-area-inset-bottom, 0));
  left: var(--space-4);
  right: var(--space-4);
  z-index: 200;
  background: var(--color-text);
  color: #fff;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.toast__undo {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
  margin-left: var(--space-3);
  flex-shrink: 0;
}

/* ── Target grid ── */
.tg-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tg-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: var(--text-sm);
}

.tg-table th,
.tg-table td {
  border: 1px solid var(--color-border);
  white-space: nowrap;
}

.tg-rep {
  position: sticky;
  left: 0;
  background: var(--color-surface);
  z-index: 2;
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  min-width: 110px;
  max-width: 140px;
}

.tg-rep--head {
  background: var(--color-bg);
  color: var(--color-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tg-month {
  padding: var(--space-2) var(--space-3);
  text-align: center;
  background: var(--color-bg);
  color: var(--color-muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  min-width: 76px;
}

.tg-cell {
  padding: var(--space-2) var(--space-3);
  text-align: right;
  cursor: pointer;
  min-width: 76px;
  transition: background 0.1s;
}

.tg-cell:hover { background: rgba(27,58,107,0.05); }

.tg-cell__val { font-weight: 600; color: var(--color-text); }
.tg-cell__ref { font-size: 0.7rem; color: var(--color-muted); margin-top: 2px; }
.tg-cell__empty { color: var(--color-muted); font-weight: 400; }

.tg-input {
  width: 70px;
  text-align: right;
  padding: 4px 6px;
  border: 1.5px solid var(--color-primary);
  border-radius: 4px;
  font-size: var(--text-sm);
  font-weight: 600;
  background: #fff;
}

.tg-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(27,58,107,0.2); }

/* ── User list ── */
.user-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.user-row__name  { font-weight: 600; margin-bottom: 2px; }
.user-row__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex-shrink: 0;
}

.btn--sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
}

/* ── Role badges ── */
.badge-role {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: 6px;
  vertical-align: middle;
}

.badge-role--rep      { background: #DBEAFE; color: #1E40AF; }
.badge-role--manager  { background: #FEF3C7; color: #92400E; }
.badge-role--exec     { background: #FCE7F3; color: #9D174D; }

/* ── Modal / sheet ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: flex-end;
}

.modal.hidden { display: none !important; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.modal__sheet {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
  max-height: 90dvh;
  overflow-y: auto;
  animation: sheetUp 0.25s ease;
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

.modal__title { font-size: var(--text-lg); font-weight: 700; color: var(--color-primary); }

.modal__close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-muted);
  cursor: pointer;
  padding: 0 4px;
}

.modal__body {
  padding: var(--space-6);
}

.modal__actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  margin-top: var(--space-4);
}

/* ── Utility ── */
.text-muted   { color: var(--color-muted); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger  { color: var(--color-danger); }
.text-right   { text-align: right; }
.text-sm      { font-size: var(--text-sm); }
.text-xs      { font-size: 0.75rem; }
.fw-bold      { font-weight: 700; }
.mt-4         { margin-top: var(--space-4); }
.mb-4         { margin-bottom: var(--space-4); }
.hidden       { display: none !important; }

/* ═══════════════════════════════════════════════════════════════
   PROMPT 5 — Visits, Stores, New Doors
   ═══════════════════════════════════════════════════════════════ */

/* ── Grade badge ───────────────────────────────────────────────── */
.grade-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 800;
  flex-shrink: 0;
  color: #fff;
  background: var(--color-muted);
}
.grade-badge--a { background: var(--grade-a); }
.grade-badge--b { background: var(--grade-b); color: #1A1D2E; }
.grade-badge--c { background: var(--color-border); color: var(--color-muted); }

/* ── Visit status colours ──────────────────────────────────────── */
.visit-status--fresh   { color: var(--color-success); }
.visit-status--warn    { color: var(--color-warning); }
.visit-status--overdue { color: var(--color-danger); }
.visit-status--never   { color: var(--color-muted); }

/* ── Status chip (analytics table) ────────────────────────────── */
.status-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-chip--ok      { background: #D1FAE5; color: #065F46; }
.status-chip--warn    { background: #FEF3C7; color: #92400E; }
.status-chip--overdue { background: #FEE2E2; color: #991B1B; }
.status-chip--never   { background: var(--color-border); color: var(--color-muted); }

/* ── [Stores | New Doors] view toggle ─────────────────────────── */
.view-toggle {
  display: inline-flex;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: var(--space-3);
}
.view-toggle__btn {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
  background: transparent;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.view-toggle__btn.active {
  background: var(--color-primary);
  color: #fff;
}

/* ── Filter row ────────────────────────────────────────────────── */
.filter-row {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--space-1);
  margin-bottom: var(--space-3);
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }

.filter-search {
  min-width: 140px;
  flex: 1;
}
.filter-select {
  min-width: 120px;
  flex-shrink: 0;
  padding-right: var(--space-6);
}

/* ── Store list row ────────────────────────────────────────────── */
.store-row {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.1s;
}
.store-row:active { box-shadow: none; }

.store-row__main {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.store-row__info { flex: 1; min-width: 0; }
.store-row__name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.store-row__sub {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.store-row__visit { text-align: right; flex-shrink: 0; }

/* ── Visit row (recent visits list) ───────────────────────────── */
.visit-row .visit-row__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-2);
}
.visit-row__note {
  margin-top: var(--space-1);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
  font-style: italic;
}

/* ── Log Visit fullscreen modal ────────────────────────────────── */
.fullscreen-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  animation: slideInFromBottom 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}
.fullscreen-modal.hidden { display: none !important; }

@keyframes slideInFromBottom {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.fullscreen-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

/* Store pick list inside log visit modal */
.store-pick-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.store-pick-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  background: var(--color-surface);
  transition: background 0.1s;
}
.store-pick-row:active { background: var(--color-bg); }
.store-pick-row__info { flex: 1; min-width: 0; }

/* Selected store card in phase 2 */
.selected-store-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  border: 2px solid var(--color-primary);
}
.selected-store-card__inner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ── Store detail slide-up sheet ───────────────────────────────── */
.detail-sheet {
  position: fixed;
  inset: 0;
  z-index: 350;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.detail-sheet.hidden { display: none !important; }
.detail-sheet.open   { transform: translateY(0); }

.detail-sheet__handle-bar {
  width: 40px;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin: var(--space-2) auto 0;
  flex-shrink: 0;
}
.detail-sheet__header {
  display: flex;
  align-items: flex-start;
  padding: var(--space-3) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  gap: var(--space-3);
  flex-shrink: 0;
}
.detail-sheet__body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-4);
}
.detail-sheet__footer {
  padding: var(--space-3) var(--space-4);
  padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

/* Key-value rows in store detail */
.detail-kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
  gap: var(--space-2);
}
.detail-kv-row:last-child { border-bottom: none; }

/* Visit history inside store detail */
.visit-hist-row {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}
.visit-hist-row:last-child { border-bottom: none; }
.visit-hist-note {
  margin-top: var(--space-1);
  color: var(--color-muted);
  font-style: italic;
}

/* ── Visit analytics table ─────────────────────────────────────── */
.analytics-table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--text-sm);
}
.analytics-table th,
.analytics-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  text-align: left;
}
.analytics-table th {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  background: var(--color-bg);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.analytics-table th:hover { color: var(--color-primary); }
.analytics-table tr:last-child td { border-bottom: none; }
.analytics-table tr:active td { background: var(--color-bg); }

/* ── New Door card ─────────────────────────────────────────────── */
.new-door-card {
  /* inherits .card styles */
  margin-bottom: var(--space-3);
}

/* ── Grade Review ──────────────────────────────────────────────── */
.gr-summary {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-1);
}
.gr-summary__item {
  flex: 1;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  text-align: center;
  border: 1px solid var(--color-border);
}
.gr-summary__item--up  { border-top: 3px solid #22c55e; }
.gr-summary__item--down { border-top: 3px solid #ef4444; }
.gr-summary__item--vm  { border-top: 3px solid var(--color-primary); }
.gr-summary__num { display: block; font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.gr-summary__lbl { display: block; font-size: 0.68rem; color: var(--color-muted); margin-top: 2px; }

.gr-section { margin-bottom: var(--space-4); }
.gr-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  font-size: 0.85rem;
}
.gr-section__header--up   { border-left: 4px solid #22c55e; }
.gr-section__header--down { border-left: 4px solid #ef4444; }
.gr-section__count {
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--color-border);
  color: var(--color-muted);
  padding: 2px 8px;
  border-radius: 99px;
}

.gr-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin-bottom: 0;
  border-radius: 0;
  border-bottom: 1px solid var(--color-border);
}
.gr-row:last-child { border-bottom: none; }
.gr-row__grades {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}
.gr-arrow {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-muted);
}
.gr-arrow--up   { color: #22c55e; }
.gr-arrow--down { color: #ef4444; }
.gr-row__info { flex: 1; min-width: 0; }
.gr-row__name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gr-row__sub  { font-size: 0.72rem; color: var(--color-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gr-row__metrics {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}
.gr-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 36px;
}
.gr-metric__val { font-size: 0.8rem; font-weight: 600; }
.gr-metric__lbl { font-size: 0.6rem; color: var(--color-muted); text-transform: uppercase; }

.gr-vm-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  flex-shrink: 0;
}
.gr-vm-badge--under { background: #fef9c3; color: #854d0e; }
.gr-vm-badge--over  { background: #fee2e2; color: #991b1b; }

/* ── Textarea ──────────────────────────────────────────────────── */
.form-textarea {
  resize: vertical;
  min-height: 80px;
}

/* ── btn-text ──────────────────────────────────────────────────── */
.btn-text {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-size: inherit;
  text-decoration: underline;
  color: inherit;
}

/* ── Section label ─────────────────────────────────────────────── */
.section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  padding: var(--space-2) 0 var(--space-1);
  margin-top: var(--space-2);
}

/* ═══════════════════════════════════════════════════════════════
   Prompt 6 — Alert Engine
   ═══════════════════════════════════════════════════════════════ */

/* ── Alert group header ──────────────────────────────────────── */
.alerts-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.alerts-group__label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-1) 0;
}

.alerts-group__label--t1 { color: var(--color-danger); }
.alerts-group__label--t2 { color: var(--color-warning); }

/* ── Alert card ──────────────────────────────────────────────── */
.alert-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  border-left: 4px solid transparent;
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  transition: opacity 0.25s;
}

.alert-card--tier1 {
  border-left-color: var(--color-danger);
  background: #FEF2F2;
}

.alert-card--tier2 {
  border-left-color: var(--color-warning);
  background: #FFFBEB;
}

.alert-card__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.alert-card__type {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-muted);
}

.alert-card--tier1 .alert-card__type { color: #B91C1C; }
.alert-card--tier2 .alert-card__type { color: #92400E; }

.alert-card__title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.alert-card__meta {
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-top: 1px;
}

.alert-card__store {
  cursor: pointer;
  color: var(--color-primary);
  text-decoration: underline;
}

.alert-card__numbers {
  font-size: 0.75rem;
  color: var(--color-muted);
}

.alert-card__risk   { color: var(--color-danger); font-weight: 600; }
.alert-card__uplift { color: var(--color-success); font-weight: 600; }

/* ── Acknowledge button ──────────────────────────────────────── */
.alert-card__ack {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-muted);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  margin-top: 2px;
}

.alert-card__ack:hover {
  background: var(--color-success);
  border-color: var(--color-success);
  color: #fff;
}

/* ── Small button variant ────────────────────────────────────── */
.btn--sm {
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
}

/* ═══════════════════════════════════════════════════════════════
   Prompt 7 — Products & Scoreboard
   ═══════════════════════════════════════════════════════════════ */

/* ── Tab bar: scrollable when 7 tabs visible (manager view) ───── */
.tab-bar {
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-bar__item {
  flex-shrink: 0;
  min-width: 56px;
}

/* ── Buying behaviour badge ────────────────────────────────────── */
.behaviour-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 700;
}
.behaviour-badge--replenisher    { background: #D1FAE5; color: #065F46; }
.behaviour-badge--rotator        { background: #DBEAFE; color: #1E40AF; }
.behaviour-badge--opportunistic  { background: #FEF3C7; color: #92400E; }
.behaviour-badge--under-optimised { background: #FEE2E2; color: #991B1B; }

/* ── Brand summary grid (products page) ────────────────────────── */
.brand-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

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

.brand-summary-card {
  text-align: center;
  padding: var(--space-3);
  margin-bottom: 0;
}
.brand-summary-card__name {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-summary-card__stat {
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--color-primary);
}
.brand-summary-card__lbl  { font-size: 0.7rem; color: var(--color-muted); }
.brand-summary-card__meta { margin-top: var(--space-1); }

/* ── SKU table ─────────────────────────────────────────────────── */
.sku-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.sku-table th {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  white-space: nowrap;
}
.sku-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.sku-table tbody tr:last-child td { border-bottom: none; }
.sku-table tbody tr:active td     { background: var(--color-bg); }

/* ── Reorder rate pill ─────────────────────────────────────────── */
.reorder-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 700;
}
.reorder-pill--high { background: #D1FAE5; color: #065F46; }
.reorder-pill--mid  { background: #FEF3C7; color: #92400E; }
.reorder-pill--low  { background: #FEE2E2; color: #991B1B; }

/* ── SKU store rows (in SKU detail sheet) ──────────────────────── */
.sku-store-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}
.sku-store-row:last-child { border-bottom: none; }
.sku-store-row:active     { background: var(--color-bg); }
.sku-store-row--dropped   { opacity: 0.65; }
.sku-store-row__info      { flex: 1; min-width: 0; }

/* ── Scoreboard ────────────────────────────────────────────────── */
.score-list { padding: 0; }

.score-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.score-row:last-child { border-bottom: none; }
.score-row--top       { background: #FFFBEB; }

.score-row__rank {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--color-border);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-muted);
  flex-shrink: 0;
}
.score-row__rank--gold {
  background: #F0B429;
  color: #fff;
}

.score-row__name {
  flex: 1;
  font-weight: 600;
  font-size: var(--text-sm);
}
.score-row__val {
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--color-primary);
  flex-shrink: 0;
}

.score-subtitle {
  font-size: 0.75rem;
  color: var(--color-muted);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  font-style: italic;
}

/* ── Import CSV data table ────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.data-table th {
  background: var(--color-bg);
  color: var(--color-muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.data-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-table tr:last-child td { border-bottom: none; }

/* Import stat pills */
.import-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}
.import-stat {
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.import-stat--ok     { background: #d1fae5; color: #065f46; }
.import-stat--warn   { background: #fef3c7; color: #92400e; }
.import-stat--muted  { background: var(--color-bg); color: var(--color-muted); border: 1px solid var(--color-border); }
