/* ============================================================
   MKRS Admin – gemensam stil
   Bygger på designen i amb-admin (app.mkrs.se): grå bakgrund, vita kort, Inter, svart som
   accentfärg. Ambassadörssektionen (/ambassadorer/, flyttad från amb-admin) använder samma
   klasser som här.
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap");
@import url("https://unpkg.com/@phosphor-icons/web@2.1.1/src/regular/style.css");
@import url("https://unpkg.com/@phosphor-icons/web@2.1.1/src/bold/style.css");

/* ============================================================
   1. FÄRGER OCH MÅTT
   ============================================================ */
:root {
  --text: #111;
  --muted: #6b6b6b;
  --bg: #f5f5f5;
  --card: #fff;
  --border: #e5e5e5;
  --hover: #fafafa;
  --black: #000;
  --success: #10b981;
  --error: #ef4444;
  --radius: 10px;

  --pos: #0a7a2f;
  --neg: #b31919;

  /* Äldre namn som sidorna använder */
  --c-bg-page: var(--bg);
  --c-bg-card: var(--card);
  --c-bg-box: var(--hover);
  --c-bg-box-hover: #f2f2f2;
  --c-border: var(--border);
  --c-border-dark: #dcdcdc;
  --c-text-main: var(--text);
  --c-text-muted: var(--muted);
  --c-pos: var(--pos);
  --c-neg: var(--neg);
  --c-neutral: #444;
  --r-card: var(--radius);
  --r-box: var(--radius);
  --r-input: 8px;
  --r-pill: 999px;
  --shadow-card: none;
}

/* ============================================================
   2. BAS
   ============================================================ */
* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  font-family: "Inter", sans-serif;
  font-size: 14px;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; }

.strong { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.small-muted { font-size: 12px; color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.link { color: inherit; font-weight: 600; text-decoration: none; cursor: pointer; background: none; border: none; padding: 0; text-align: left; }
.link:hover { text-decoration: underline; }
a.subtle { color: inherit; text-decoration: none; }
a.subtle:hover { text-decoration: underline; }

/* Diff mot fg år */
.badge-positive { color: var(--pos); font-weight: 600; }
.badge-negative { color: var(--neg); font-weight: 600; }
.badge-neutral  { color: var(--muted); font-weight: 600; }

.state-message, .analysis-state, .dashboard-state, .amb-empty, .orders-empty { margin: 10px 0; font-size: 14px; color: var(--muted); }
.meta { font-size: 13px; color: var(--muted); white-space: nowrap; }
.cell-sub, .stat-sub, .summary-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.35; }

/* ============================================================
   3. KNAPPAR, FÄLT OCH ETIKETTER
   ============================================================ */
.btn, .link-btn, .refresh-btn, .timeseries-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: opacity 0.15s, background 0.15s;
}
.btn:hover, .link-btn:hover, .refresh-btn:hover, .timeseries-toggle-btn:hover { background: var(--hover); }
.btn:disabled, .link-btn.disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--black); border-color: var(--black); color: #fff; }
.btn-primary:hover { background: var(--black); opacity: 0.85; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(0, 0, 0, 0.05); }
.btn-sm, .link-btn, .timeseries-toggle-btn { padding: 6px 10px; font-size: 13px; }
.btn-icon { padding: 6px 8px; font-size: 16px; }
.btn-block { width: 100%; padding: 14px; font-size: 15px; }

.input, .select,
.select-wrap select, .range-select select, .search-box input, .custom-range-row input[type="date"] {
  width: auto;
  max-width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  outline: none;
}
.input:focus, .select:focus,
.select-wrap select:focus, .range-select select:focus, .search-box input:focus, .custom-range-row input:focus {
  border-color: var(--black);
  box-shadow: 0 0 0 1px var(--black);
}
.input:disabled { background: var(--bg); color: var(--muted); }
textarea.input { resize: vertical; min-height: 80px; line-height: 1.5; }
.search { flex: 1; min-width: 200px; }

.badge, .code-pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--bg); }
.code-pill { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.status-pending   { background: #eef2ff; color: #4338ca; }
.status-offered   { background: #fef3c7; color: #92400e; }
.status-confirmed { background: #d1fae5; color: #065f46; }
.status-declined  { background: #f3f4f6; color: #4b5563; }
.status-rejected  { background: #fee2e2; color: #991b1b; }
.status-draft     { background: #f3f4f6; color: #4b5563; }
.status-open      { background: #d1fae5; color: #065f46; }
.status-completed { background: #e5e7eb; color: #111; }
.status-ok        { background: #d1fae5; color: #065f46; }
.status-error     { background: #fee2e2; color: #991b1b; }
.status-new       { background: #f3f4f6; color: #4b5563; }

select.status-select { padding: 5px 8px; border-radius: 999px; border: none; font-size: 12px; font-weight: 600; cursor: pointer; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip .count { color: var(--muted); font-weight: 500; margin-left: 4px; }
.chip.active { background: var(--black); border-color: var(--black); color: #fff; }
.chip.active .count { color: rgba(255, 255, 255, 0.7); }

/* Segmenterad växel (t.ex. flikar inom en sida) */
.segmented { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 16px; background: #eaeaea; border-radius: 8px; max-width: 100%; overflow-x: auto; }
.seg { border: none; background: none; padding: 7px 14px; border-radius: 6px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

/* Radioknappar som väljer vy (Stad/Kommun/Län/Land, Nuläge/Prognos) */
.filters, .geo-tabs, .mode-switch { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.mode-switch label, .geo-tabs label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; font-weight: 600; }
.mode-switch input[type="radio"], .geo-tabs input[type="radio"] { margin: 0; accent-color: var(--black); }

/* ============================================================
   4. SIDHUVUD OCH MENY
   ============================================================ */
#header-container { position: sticky; top: 0; z-index: 50; }

.topbar { background: var(--card); border-bottom: 1px solid var(--border); position: relative; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; height: 60px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; white-space: nowrap; color: inherit; text-decoration: none; }
.brand-logo { height: 24px; width: auto; display: block; }
.brand span { font-weight: 500; color: var(--muted); }

.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 8px 12px; border-radius: 8px; font-weight: 600; color: var(--muted); text-decoration: none; white-space: nowrap; }
.tab:hover, .tab.active { color: var(--text); background: var(--bg); }
.tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 4px;
  border-radius: 999px; background: var(--error); color: #fff; font-size: 11px; font-weight: 700;
}

.user { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.topbar-current { display: none; font-weight: 700; flex: 1; text-align: center; }
.menu-btn { display: none; }
.nav-user { display: none; }

/* Namnet på den inloggade tar plats från flikarna */
@media (max-width: 1439px) { .user [data-user-email] { display: none; } }

/* Under 1180 px får flikarna inte plats: sidans namn i mitten och meny bakom knappen */
@media (max-width: 1179px) {
  .topbar-inner { gap: 12px; }
  .topbar-current { display: block; }
  .menu-btn { display: inline-flex; }
  .user { display: none; }
  .main-nav {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; gap: 2px;
    padding: 8px 16px 14px;
    background: var(--card); border-bottom: 1px solid var(--border);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
    overflow: visible;
  }
  .main-nav.open { display: flex; }
  .main-nav .tab { padding: 11px 12px; font-size: 15px; }
  .nav-user { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; padding: 12px 12px 0; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
  .nav-user span { overflow: hidden; text-overflow: ellipsis; }
}

/* Undermeny i en sektion (Ambassadörer) */
.subnav { background: var(--card); border-bottom: 1px solid var(--border); }
.subnav-inner { max-width: 1280px; margin: 0 auto; padding: 6px 16px; display: flex; align-items: center; gap: 12px; }
.subnav .tabs { flex: 1; min-width: 0; }
.subnav-actions { display: flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
@media (max-width: 760px) { .subnav-actions #lastRefresh { display: none; } }

.mkrs-footer { max-width: 1280px; margin: 24px auto 32px; padding: 0 16px; text-align: center; font-size: 12px; color: var(--muted); }
.mkrs-footer hr { border: none; border-top: 1px solid var(--border); margin: 0 0 12px; }

/* ============================================================
   5. INLOGGNING (auth.js)
   ============================================================ */
html.mkrs-locked body > :not(.mkrs-auth-view) { display: none !important; }

.center-view { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--black); }
.login-card { width: 100%; max-width: 420px; background: var(--bg); border-radius: 16px; overflow: hidden; }
.login-logo { width: 100%; display: block; background: #fff; border-bottom: 1px solid var(--border); }
.login-inner { padding: 28px 24px; text-align: center; }
.login-inner h1 { margin: 0 0 8px; font-size: 24px; }
.login-inner p { margin: 0 0 24px; color: var(--muted); line-height: 1.5; word-break: break-word; }
.msg { margin-top: 16px; padding: 12px 14px; border-radius: 8px; font-size: 14px; line-height: 1.4; text-align: left; }
.msg-error { background: #fef2f2; color: var(--error); border: 1px solid #fecaca; }

.spinner { width: 30px; height: 30px; border: 3px solid rgba(255, 255, 255, 0.25); border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   6. SIDLAYOUT
   ============================================================ */
.main, .page-container { max-width: 1280px; margin: 0 auto; padding: 24px 16px 48px; }
.view-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.view-header h1 { margin: 0; font-size: 22px; }

/* Eventväljaren i rubriken på Eventanalys-flikarna (layout.js, MKRS_EVENT.picker) */
.event-title { position: relative; }
.event-picker { display: inline-flex; align-items: baseline; gap: 8px; margin: -4px -10px; padding: 4px 10px; border: 0; border-radius: 8px; background: none; color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.event-picker:hover, .event-picker[aria-expanded="true"] { background: var(--card); box-shadow: inset 0 0 0 1px var(--border); }
.event-picker:focus-visible { outline: 2px solid var(--black); outline-offset: 2px; }
.event-picker .ep-label-year { color: var(--muted); }
.event-picker i { align-self: center; font-size: 14px; color: var(--muted); }
.ep-pop { position: absolute; top: calc(100% + 8px); left: -10px; z-index: 40; width: max-content; min-width: 300px; max-width: min(460px, calc(100vw - 32px)); max-height: min(420px, 70vh); overflow-y: auto; padding: 6px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14); font-size: 14px; font-weight: 400; }
.ep-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 12px; padding: 4px 6px 4px 10px; border-radius: 8px; }
.ep-row.selected { background: var(--bg); }
.ep-name { flex: 1 0 auto; max-width: 100%; padding: 6px 0; border: 0; background: none; color: var(--text); font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
.ep-name:disabled { color: var(--muted); cursor: default; }
.ep-years { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.ep-year { padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--card); color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.ep-year:hover:not(:disabled) { border-color: var(--black); }
.ep-year.active { background: var(--black); border-color: var(--black); color: #fff; }
.ep-year:disabled { opacity: 0.35; cursor: default; }
.event-note { margin: -8px 0 16px; color: var(--muted); font-size: 13px; }
@media (max-width: 600px) {
  .view-header h1.event-title { flex: 1 1 100%; font-size: 20px; }
  .ep-pop { left: 0; right: 0; width: auto; min-width: 0; max-width: none; }
}
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

/* Väljarna i sidhuvudet (Evenemang, År …) visas utan rubrik, som i amb-admin */
.select-wrap, .range-select { position: relative; }
.view-header .select-wrap label, .view-header .range-select label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.view-header .select-wrap select, .view-header .range-select select { min-width: 160px; }
.select-wrap label, .range-select label, .custom-range-row label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.card-pad { padding: 16px; }
.table-wrap, .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.empty-card { padding: 40px 16px; text-align: center; color: var(--muted); }

.header-block, .top-bar, .section-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.section-title { margin: 24px 0 8px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.section-header .section-title { margin: 0; }

/* Kort med innehåll */
.dash-box, .analysis-box, .stat-box, .sum-card, .event-card, .detail-box, .account-card, .metric-card, .summary-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Rubriker i korten */
.dash-subtitle, .analysis-subtitle, .stat-label, .sum-card-title, .detail-title, .summary-title, .account-card-title, .event-section-title, .fb-stat-label {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.fb-card-head { font-weight: 700; margin-bottom: 12px; }

/* Nyckeltal */
.stat-value, .summary-value, .fb-stat-value { font-size: 28px; font-weight: 700; line-height: 1.15; letter-spacing: -0.01em; }
.fb-stat-sub { margin-top: 2px; font-size: 13px; color: var(--muted); }

/* Rutnät */
.dash-grid, .analysis-grid, .events-grid, .grid, .summary-grid, .detail-grid, .account-cards { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.fb-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 12px; }
.fb-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 12px; }
.fb-stat, .fb-card { padding: 16px; }
.fb-card + .fb-card { margin-top: 12px; }
.fb-grid .fb-card + .fb-card { margin-top: 0; }

@media (min-width: 900px) {
  .dash-grid, .analysis-grid, .summary-grid, .detail-grid, .account-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .events-grid { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
  .grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
  .span-2 { grid-column: span 2; }
}

/* ============================================================
   7. TABELLER
   ============================================================ */
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; background: var(--hover); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--hover); }
td.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.th-sort { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.th-sort::after { content: '↕'; opacity: 0.35; }
.th-sort:hover, th[aria-sort="ascending"], th[aria-sort="descending"] { color: var(--text); }
th[aria-sort="ascending"] .th-sort::after { content: '↑'; opacity: 1; }
th[aria-sort="descending"] .th-sort::after { content: '↓'; opacity: 1; }
.th-sort:focus-visible { outline: 2px solid var(--black); outline-offset: 2px; border-radius: 3px; }

/* Tabeller i kort har ingen egen ram; fristående tabeller får kortets ram */
.cmp, .geo-table { border: 1px solid var(--border); border-radius: var(--radius); border-collapse: separate; border-spacing: 0; overflow: hidden; }
.cmp td, .geo-table td { border-bottom: 1px solid var(--border); }
/* … men inte inuti ett kort, där kortet redan har ramen */
.dash-box .cmp, .analysis-box .geo-table, .sum-card .geo-table, .detail-box .cmp, .card .cmp { border: none; border-radius: 0; }
.cmp tbody tr:last-child td, .geo-table tbody tr:last-child td { border-bottom: none; }
.dash-box table, .analysis-box table, .sum-card table, .detail-box table, .account-card table, .event-card table { font-size: 13px; }

.num, td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.num { font-weight: 600; }
.rank { width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 700; }

.group-row td { background: var(--bg); font-weight: 700; }
.total-row td { font-weight: 700; border-top: 2px solid var(--border); }
tr.amb-row, tr.order-row { cursor: pointer; }

.compare th.num, .compare td.num { text-align: right; font-variant-numeric: tabular-nums; }
.compare tr.current td { font-weight: 700; background: var(--hover); }

/* ============================================================
   8. DIALOGER OCH FORMULÄR
   ============================================================ */
dialog { border: none; border-radius: 14px; padding: 0; width: min(580px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
dialog[open] { display: flex; }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog form { display: flex; flex-direction: column; width: 100%; max-height: calc(100vh - 32px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 14px 20px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-body { padding: 20px; overflow-y: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--hover); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .input, .field .select { width: 100%; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
.hint code { background: var(--bg); color: var(--text); padding: 1px 5px; border-radius: 4px; font-size: 11px; }
.check-row { display: flex !important; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.check-row input { width: 18px; height: 18px; accent-color: var(--black); }
.check-list { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.check-list label { display: flex; align-items: center; gap: 6px; font-weight: 500; cursor: pointer; }
.check-list input { width: 16px; height: 16px; accent-color: var(--black); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 10px; background: var(--black); color: #fff; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); z-index: 100; }
.toast.error { background: var(--error); }

/* ============================================================
   9. STAPLAR, AI-SAMMANFATTNINGAR OCH FRITEXTSVAR
   ============================================================ */
.bar-row { display: grid; grid-template-columns: minmax(80px, 160px) 1fr 80px; align-items: center; gap: 10px; padding: 5px 0; font-size: 13px; }
.bar-row .bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-value { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--black); border-radius: 999px; }

.fb-open { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
@media (max-width: 760px) { .fb-open { grid-template-columns: minmax(0, 1fr); } }
.fb-answers { display: flex; flex-direction: column; gap: 8px; max-height: 520px; overflow-y: auto; }
.fb-answer { background: var(--bg); border-left: 3px solid var(--black); border-radius: 8px; padding: 10px 12px; font-size: 14px; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
.fb-answer .meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; white-space: normal; }

.ai-box { background: var(--hover); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.ai-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.ai-badge { display: inline-flex; align-items: center; gap: 5px; background: var(--black); color: #fff; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 3px 8px; border-radius: 999px; }
.ai-content { font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.ai-content p { margin: 0 0 8px; }
.ai-content p:last-child { margin-bottom: 0; }
.ai-meta { margin-top: 10px; font-size: 12px; color: var(--muted); }
.ai-meta:empty { display: none; }
.ai-wait { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.ai-wait .spinner { width: 16px; height: 16px; border-width: 2px; border-color: var(--border); border-top-color: var(--black); flex: none; }
.ai-error { color: var(--error); }

/* ============================================================
   10. SIDSPECIFIKT
   ============================================================ */

/* Dashboard: ett kort per evenemang */
.event-header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.event-name { font-size: 18px; font-weight: 700; }
.event-key { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
a.event-link { text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
a.event-link:hover { color: var(--text); }
.event-metrics { font-size: 13px; line-height: 1.5; }
.metric-value { font-weight: 700; }
.orders-summary { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--c-border-dark); font-size: 12px; display: flex; justify-content: space-between; gap: 12px; }
.orders-hide-mobile { display: table-cell; }
.collapsible-section { margin-top: 4px; border-top: 1px solid var(--border); padding-top: 12px; }
.collapsible-header { display: flex; justify-content: space-between; align-items: center; }
.section-content { display: none; margin-top: 12px; }
.section-content.is-visible { display: block; }
.orders-chev-col { width: 18px; }
.orders-chev { display: inline-block; font-size: 16px; color: var(--muted); transition: transform 0.2s ease; }
tr[aria-expanded="true"] .orders-chev { transform: rotate(90deg); color: var(--text); }
.order-detail-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
tr.detail-row td { background: var(--card); padding: 12px; }
.detail-wrap { display: grid; grid-template-columns: 1fr; gap: 12px; }

/* Analys: Från/Till visas bara för "Anpassat intervall" (analys sätter display: flex) */
.custom-range-row { display: none; gap: 12px; flex-wrap: wrap; margin: 0 0 16px; }
.custom-range-row > div { flex: 1 1 160px; max-width: 220px; }
.custom-range-row input[type="date"] { width: 100%; }

/* Analys: diagrammet ritas med maintainAspectRatio: false och behöver en höjd att fylla */
.timeseries-chart-container { position: relative; height: 260px; margin-bottom: 10px; }

/* Analys: ålder */
.age-chart { margin-top: 4px; }
.age-header-row, .age-row { display: grid; grid-template-columns: 70px 1fr 60px 60px 60px; gap: 8px; font-size: 13px; align-items: center; }
.age-row { padding: 3px 0; }
.age-header-row { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; margin-bottom: 6px; }
.age-header-row div:nth-child(n+3) { text-align: right; }
.age-label { font-weight: 600; }
.age-bar-outer { height: 10px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.age-bar-inner { height: 100%; border-radius: inherit; background: var(--black); }
.age-count { text-align: right; font-variant-numeric: tabular-nums; }

/* Statistik: rubriken Nuläge/Prognos i tabellens kort */
.mode-subheader { margin: 0; padding: 14px 16px 10px; font-size: 15px; }

/* Ambassadörer (säljstatistik): sammanställningen och geografin bredvid varandra */
.summary-row { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); margin-bottom: 16px; }
@media (min-width: 900px) { .summary-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.summary-box { padding: 12px 14px; background: var(--hover); }
.search-box { flex: 1; min-width: 220px; }
.search-box input { width: 100%; }

/* ============================================================
   11. MOBIL
   ============================================================ */
@media (max-width: 700px) {
  .main, .page-container { padding: 16px 12px 40px; }
  .view-header h1 { font-size: 20px; }
  .view-header .filters, .view-header .toolbar { width: 100%; }
  .view-header .select-wrap, .view-header .range-select { flex: 1 1 140px; }
  .view-header .select-wrap select, .view-header .range-select select { width: 100%; min-width: 0; }
  .search-box { min-width: 100%; }

  /* Nyckeltal två per rad */
  .grid, .summary-grid, .top-metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .stat-value, .summary-value, .fb-stat-value { font-size: 22px; }
  .stat-box, .metric-card, .fb-stat { padding: 12px; }

  th, td { padding: 8px 8px; }
  .orders-hide-mobile { display: none; }
  .event-name { font-size: 16px; }

  /* Datatabeller: första kolumnen står kvar när man scrollar i sidled */
  .table-wrapper table td:first-child, .table-wrapper table th:first-child,
  .table-wrap table.sticky-first td:first-child, .table-wrap table.sticky-first th:first-child {
    position: sticky; left: 0; z-index: 1; background: var(--card);
  }
  .table-wrapper table th:first-child { background: var(--hover); }
  .table-wrapper table td:first-child, .table-wrapper table th:first-child { max-width: 42vw; white-space: normal; }
  .table-wrapper .group-row td:first-child { background: var(--bg); }

  /* Historik/geografi: tighta tabeller */
  .cmp { table-layout: fixed; font-size: 12px; }
  .cmp td.num, .cmp th.num { white-space: normal; }
  .cmp td:first-child, .cmp th:first-child { width: 56px; white-space: nowrap; }
  /* Breda tabeller (Försäljning) scrollar i sidled i stället */
  .cmp.wide { table-layout: auto; min-width: 520px; }
  .cmp.wide td.num, .cmp.wide th.num { white-space: nowrap; }
  .cmp.wide td:first-child, .cmp.wide th:first-child { width: auto; }

  /* Ålder: stapeln får en egen rad under siffrorna, annars blir den bara en prick */
  .age-row, .age-header-row { grid-template-columns: 1fr 44px 56px 56px; }
  .age-row { grid-template-areas: "label count ret new" "bar bar bar bar"; row-gap: 3px; margin-bottom: 4px; }
  .age-row > :nth-child(1) { grid-area: label; }
  .age-row > :nth-child(2) { grid-area: bar; height: 8px; }
  .age-row > :nth-child(3) { grid-area: count; }
  .age-row > :nth-child(4) { grid-area: ret; }
  .age-row > :nth-child(5) { grid-area: new; }
  .age-header-row > :nth-child(2) { display: none; }
  .custom-range-row > div { max-width: none; }
  .timeseries-chart-container { height: 220px; }
  .geo-tabs { gap: 10px; font-size: 12px; }

  /* Listor som kort: varje rad blir ett kort, rubriken står framför värdet (se .card-list) */
  table.card-list thead { display: none; }
  table.card-list, table.card-list tbody { display: block; background: none; }
  table.card-list tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  table.card-list tbody tr:last-child { border-bottom: none; }
  table.card-list td { display: block; padding: 0; border: none; min-width: 0; text-align: left; overflow-wrap: anywhere; }
  table.card-list td.num { text-align: left; }
  table.card-list td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 2px; }
  table.card-list tr { position: relative; }
  table.card-list td.cl-title { grid-column: 1 / -1; font-size: 15px; }
  table.card-list tr.has-check td.cl-title { padding-right: 36px; }
  table.card-list td.cl-check { position: absolute; top: 12px; right: 14px; }
  table.card-list td.cl-check input { width: 18px; height: 18px; }
  table.card-list td.cl-full { grid-column: 1 / -1; }
  table.card-list td.cl-hide { display: none; }
  table.card-list td.empty { grid-column: 1 / -1; padding: 24px 0; text-align: center; }
}
