/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button:focus, button:focus-visible,
select:focus, select:focus-visible,
[tabindex]:focus, [tabindex]:focus-visible { outline: none; }

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --surface-3: #eceef3;
  --border: #dde1e9;
  --accent: #A856F7;
  --accent-dim: rgba(168,86,247,0.08);
  --text: #1a1730;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --success: #16a34a;
  --sidebar-width: 168px;
  --sidebar-collapsed: 0px;
  --header-h: 52px;
  --radius: 8px;
  --radius-sm: 5px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-weight: 400;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout shell ───────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  gap: 12px;
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 12px; }

.logo {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
}

.store-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* Hamburger button */
.sidebar-toggle {
  width: 32px; height: 32px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.sidebar-toggle:hover { background: var(--surface-3); color: var(--text); }
.sidebar-toggle span {
  display: block;
  width: 16px; height: 1.5px;
  background: currentColor;
  border-radius: 2px;
  transition: opacity 0.15s;
}

/* Body layout */
.app-body {
  display: flex;
  margin-top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.22s cubic-bezier(0.4,0,0.2,1);
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
  border-right-width: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  gap: 2px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 14px;
  height: 40px;
  background: none;
  border: none;
  border-radius: 0;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font);
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.12s, color 0.12s;
  position: relative;
  width: 100%;
  text-align: left;
  outline: none;
}
.nav-tab:focus, .nav-tab:focus-visible { outline: none; }

.nav-tab:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-tab.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-tab.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.tab-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
}

.tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.15s;
}

.sidebar.collapsed .tab-label {
  opacity: 0;
  pointer-events: none;
}

/* ── Main content ───────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Tab panels — constrained to viewport, internal scroll per-section */
.tab-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  height: 100%;
  min-height: 0;
  position: relative;
}
.tab-panel.active { display: flex; }

.panel-header {
  padding: 28px 28px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-header h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.4px;
}

.panel-subtitle {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.coming-soon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-dim);
  font-size: 14px;
  letter-spacing: 0.5px;
}

/* ── Upload grid ────────────────────────────────────────────── */
.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(231px, 1fr));
  gap: 10px;
  padding: 0 28px 0;
}

.upload-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
  height: 66px;
  box-sizing: border-box;
}

.upload-card:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}

.upload-card.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.upload-card.loaded {
  border-color: var(--success);
}

.upload-card-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: 100%;
  box-sizing: border-box;
  pointer-events: none;
}

.upload-card-inner svg {
  width: 20px; height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.upload-card.loaded .upload-card-inner svg {
  color: var(--success);
}

.upload-title {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--text);
}

.upload-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.upload-badge {
  margin-left: auto;
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--surface-3);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.upload-card.loaded .upload-badge {
  background: rgba(22, 163, 74, 0.12);
  color: var(--success);
}

.file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.manual-card .file-input { display: none; }

/* ── Raw data mode toggle ────────────────────────────────────── */
.raw-mode-bar {
  padding: 20px 28px 16px;
  display: flex;
  align-items: center;
}

/* ── API connection grid ─────────────────────────────────────── */
.api-grid {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(231px, 1fr));
  gap: 10px;
  padding: 0 28px 0;
}
.api-grid.visible { display: grid; }

.api-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
  height: 66px;
  box-sizing: border-box;
  overflow: hidden;
}
.api-card.connected { border-color: var(--success); }

.api-card-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: 100%;
  box-sizing: border-box;
}
.api-card-inner svg {
  width: 20px; height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.api-card.connected .api-card-inner svg { color: var(--success); }

.api-title {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--text);
}
.api-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.api-badge {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--surface-3);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.api-card.connected .api-badge {
  background: rgba(22, 163, 74, 0.12);
  color: var(--success);
}

.api-connect-btn {
  flex-shrink: 0;
  margin-left: 0;
  height: 22px;
  padding: 0 10px;
  font-size: 11.5px;
  font-weight: 500;
  font-family: var(--font);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.12s;
}
.api-connect-btn:hover { opacity: 0.85; }
.api-card.connected .api-connect-btn {
  background: var(--surface-3);
  color: var(--text-muted);
}

.api-card-right {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.btn-secondary {
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text);
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.12s, border-color 0.12s;
  flex-shrink: 0;
  margin-left: auto;
  font-family: var(--font);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--accent); }

/* ── Data source bar ────────────────────────────────────────── */
.data-source-bar {
  display: flex;
  gap: 2px;
  padding: 16px 28px 0;
  border-bottom: 1px solid var(--border);
}

.source-tab {
  padding: 7px 14px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12.5px;
  font-family: var(--font);
  transition: color 0.12s, border-color 0.12s;
  margin-bottom: -1px;
}

.source-tab:hover { color: var(--text); }

.source-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Spreadsheet table ──────────────────────────────────────── */
.table-wrapper {
  flex: 1;
  overflow: auto;
  position: relative;
}

.table-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  min-height: 260px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.6;
}

.table-empty svg {
  width: 48px; height: 48px;
  opacity: 0.2;
}

.table-empty p { font-size: 13px; }

/* ── Shopify instructions empty state ───────────────────────── */
.table-empty:has(.empty-instructions) {
  align-items: flex-start;
  justify-content: flex-start;
  padding: 28px 32px;
}

.empty-instructions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
  max-width: 520px;
  text-align: left;
}

.empty-instructions-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  counter-reset: steps;
}

.empty-instructions-steps li {
  counter-increment: steps;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.5;
}

.empty-instructions-steps li::before {
  content: counter(steps);
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  background: var(--accent-dim);
  border: 1px solid rgba(168, 86, 247, 0.3);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.empty-instructions-cols {
  display: flex;
  gap: 40px;
}

.empty-instructions-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--accent);
}

.empty-instructions-section ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.empty-instructions-section li {
  font-size: 13px;
  color: var(--text-muted);
  padding-left: 12px;
  position: relative;
}

.empty-instructions-section li::before {
  content: '–';
  position: absolute;
  left: 0;
  color: var(--text-dim);
}

.empty-instructions-guide {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-guide-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--accent);
}

.empty-guide-steps {
  list-style: none;
  counter-reset: guide;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.empty-guide-steps li {
  counter-increment: guide;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.empty-guide-steps li::before {
  content: counter(guide);
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.empty-guide-steps li strong {
  color: var(--text);
  font-weight: 500;
}

.empty-instructions-video {
  font-size: 12px;
  color: var(--text-dim);
}

.video-link-placeholder {
  color: var(--accent);
  opacity: 0.6;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font);
  font-size: 13px;
  display: none;
}

.data-table.visible { display: table; }

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.data-table th {
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  border-bottom: 2px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  font-weight: 500;
  font-family: var(--font);
  font-size: 11.5px;
  color: var(--text-muted);
  letter-spacing: 0.3px;
  white-space: nowrap;
  user-select: none;
}

.data-table th:first-child {
  background: var(--surface-3);
  color: var(--text-dim);
  width: 48px;
  text-align: center;
}

.data-table td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  white-space: nowrap;
  color: var(--text);
  font-weight: 400;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table td:first-child {
  background: var(--surface-2);
  color: var(--text-dim);
  text-align: center;
  font-size: 11px;
  border-right: 2px solid var(--border);
  user-select: none;
}

.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table tbody tr:hover td:first-child { background: var(--surface-3); }

/* ── Ad Spend Split bar ──────────────────────────────────────── */
.ad-split-bar {
  display: none;
  align-items: center;
  gap: 24px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ad-split-bar.visible { display: flex; }
.ad-split-group {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
}
.ad-split-fields {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ad-split-label {
  font-size: 13px;
  color: var(--text-muted);
}
.ad-split-input {
  width: 48px;
  height: 28px;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--font);
  font-size: 13px;
  line-height: 26px;
  color: var(--text);
  padding: 0 6px;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}
.ad-split-input::-webkit-outer-spin-button,
.ad-split-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ad-split-input:focus { outline: none; border-color: var(--accent); }
.ad-split-input::placeholder { color: var(--text-muted); text-align: center; }
.ad-split-ret {
  font-size: 13px;
  color: var(--text-muted);
}
.ad-split-currency-group {
  padding-left: 24px;
  border-left: 1px solid var(--border);
}
.currency-select-wrap {
  display: flex;
  align-items: center;
  position: relative;
}
.currency-select-input { display: none; }

/* ── Manual Inputs inline panel ─────────────────────────────── */
.manual-inline {
  display: none;
  flex-direction: column;
  height: 100%;
}

.manual-inline.visible { display: flex; }

/* Blocked state */
.manual-blocked {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex: 1;
  text-align: center;
  color: var(--text-dim);
  padding: 40px;
}

.manual-blocked svg {
  width: 48px; height: 48px;
  opacity: 0.2;
}

.blocked-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

.blocked-hint {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.7;
}

/* Active grid */
.manual-grid-wrap {
  display: none;
  flex: 1;
  overflow: auto;
}

.manual-inline-grid {
  display: grid;
  grid-template-columns: 160px repeat(6, minmax(150px, 1fr));
  width: 100%;
}

/* Sticky header row */
.manual-inline-grid .grid-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  border-bottom: 2px solid var(--border);
  padding: 8px 12px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.3px;
  white-space: nowrap;
  user-select: none;
}

.manual-inline-grid .grid-header:first-child {
  background: var(--surface-3);
  color: var(--text-dim);
}

/* Month label cells */
.manual-inline-grid .grid-month {
  background: var(--surface-2);
  border-right: 2px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

/* Input cells */
.manual-inline-grid input[type="text"] {
  background: var(--surface);
  border: none;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  width: 100%;
  outline: none;
  transition: background 0.12s;
  cursor: default;
}

.manual-inline-grid input[type="text"]:focus {
  background: var(--surface-3);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
  position: relative;
  cursor: text;
}

.manual-inline-grid input[type="text"].cell-selected {
  background: rgba(168, 86, 247, 0.22);
  box-shadow: inset 0 0 0 1px rgba(168, 86, 247, 0.5);
}

.manual-inline-grid input[type="text"].cell-selected:focus {
  background: rgba(168, 86, 247, 0.18);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.manual-inline-grid input[type="text"]::placeholder {
  color: var(--text-dim);
  font-weight: 400;
}

/* ── P&L Breakdown ──────────────────────────────────────────── */
.pnl-filters {
  display: flex;
  align-items: flex-end;
  gap: 24px;
  padding: 16px 28px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.pnl-filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pnl-filter-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.pnl-date-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pnl-date-sep {
  font-size: 12px;
  color: var(--text-dim);
}

.pnl-date-field {
  position: relative;
  display: flex;
  align-items: center;
}
.pnl-date-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12.5px;
  padding: 7px 32px 7px 10px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  width: 126px;
}
.pnl-date-input:focus, .pnl-date-input.open { border-color: var(--accent); }
.pnl-date-cal-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  transition: color 0.12s;
}
.pnl-date-cal-btn svg { width: 14px; height: 14px; }
.pnl-date-cal-btn:hover { color: var(--text-muted); }

/* ── Custom calendar popup ──────────────────────────────────────── */
.pnl-cal {
  position: absolute;
  top: 0;
  left: 0;
  width: 252px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.10);
  z-index: 100;
  display: none;
  flex-direction: column;
  padding: 14px 16px 10px;
  font-family: var(--font);
}
.pnl-cal.open { display: flex; }

.pnl-cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.pnl-cal-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}
.pnl-cal-nav {
  display: flex;
  gap: 2px;
}
.pnl-cal-nav-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 3px 5px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  transition: background 0.1s, color 0.1s;
}
.pnl-cal-nav-btn svg { width: 14px; height: 14px; }
.pnl-cal-nav-btn:hover { background: var(--surface-2); color: var(--text); }

.pnl-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px 0;
  margin-bottom: 8px;
}
.pnl-cal-dh {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-align: center;
  padding-bottom: 6px;
}
.pnl-cal-day {
  font-size: 12.5px;
  color: var(--text);
  text-align: center;
  padding: 5px 0;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.pnl-cal-day:hover { background: var(--accent-dim); color: var(--accent); }
.pnl-cal-day.pnl-cal-other { color: var(--text-dim); }
.pnl-cal-day.pnl-cal-today { color: var(--accent); font-weight: 600; }
.pnl-cal-day.pnl-cal-selected {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.pnl-cal-day.pnl-cal-selected:hover { background: var(--accent); color: #fff; }

.pnl-cal-footer {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.pnl-cal-foot-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.12s;
}
.pnl-cal-foot-btn:hover { color: var(--text); }
.pnl-cal-foot-today { color: var(--accent); }
.pnl-cal-foot-today:hover { color: var(--accent); opacity: 0.8; }
.pnl-filters *:focus { outline: none; }
.pnl-filters *:focus-visible { outline: none; }

.pnl-seg {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.seg-btn {
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 14px;
  height: auto;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: var(--surface-3); color: var(--text); }
.seg-btn.active {
  background: var(--accent);
  color: #fff;
}


/* ── Customise button ────────────────────────────────────────── */
.pnl-customise-btn {
  flex-shrink: 0;
  margin-left: 8px;
  height: auto;
  padding: 7px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12.5px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  white-space: nowrap;
}
.pnl-customise-btn:hover,
.pnl-customise-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ── Customise drawer ────────────────────────────────────────── */
.pnl-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: 260px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 30;
  box-shadow: -4px 0 16px rgba(0,0,0,0.06);
}
.pnl-drawer.open {
  transform: translateX(0);
}

.pnl-drawer-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pnl-drawer-search-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
}
.pnl-drawer-search {
  width: 100%;
  height: 30px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12.5px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.pnl-drawer-search::placeholder { color: var(--text-dim); }
.pnl-drawer-search:focus { border-color: var(--accent); background: var(--surface); }
.pnl-drawer-search-clear {
  display: none;
  position: absolute;
  right: 7px;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  background: var(--surface-3);
  border-radius: 50%;
  cursor: pointer;
  font-size: 9px;
  color: var(--text-dim);
  line-height: 1;
  padding: 0;
  transition: background 0.12s, color 0.12s;
}
.pnl-drawer-search-clear:hover { background: var(--border); color: var(--text); }
.pnl-drawer-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.12s;
}
.pnl-drawer-close:hover { color: var(--text); }

.pnl-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0 8px;
}


.pnl-drawer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  font-size: 12.5px;
  color: var(--text-muted);
  transition: background 0.1s;
}
.pnl-drawer-row:hover { background: var(--surface-2); }
.pnl-drawer-row input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.pnl-drawer-row .pnl-drawer-scale-check {
  accent-color: #8264d2;
}
.pnl-drawer-row-label {
  flex: 1;
  cursor: pointer;
  user-select: none;
}

.pnl-drawer-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 16px;
}
.pnl-drawer-no-results {
  padding: 20px 16px;
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
}

/* Make the P&L tab relative so drawer can position inside it */
#tab-pnl { position: relative; }

.pnl-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex: 1;
  min-height: 260px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.6;
}
.pnl-empty svg { width: 48px; height: 48px; opacity: 0.25; }
.pnl-empty p { font-size: 13px; }

/* P&L tab: constrain to viewport so table-wrap is the scroll container */
#tab-pnl {
  height: 100%;
  min-height: 0;
}

.pnl-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  position: relative;
  scrollbar-width: none; /* Firefox */
  outline: none;
}
.pnl-table-wrap::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.pnl-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
  font-family: var(--font);
  width: max-content;
}

.pnl-th-period,
.pnl-td:not(.pnl-td-metric) {
  width: 90px;
  min-width: 90px;
  max-width: 90px;
}

/* Sticky header cells */
.pnl-table th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  border-bottom: 2px solid var(--border);
  padding: 8px 14px;
  text-align: center;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Sticky metric column — both th (corner) and td (data rows) */
.pnl-th-metric,
.pnl-td-metric {
  position: sticky !important;
  left: 0 !important;
  width: 1%;
  white-space: nowrap;
  /* Shadow on right edge to separate from scrolling columns */
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.07);
  clip-path: inset(0 -10px 0 0); /* let shadow escape clipping */
}

/* Top-left corner: sticky both axes */
.pnl-th-metric {
  position: sticky !important;
  top: 0 !important;
  left: 0 !important;
  background: var(--surface-2) !important;
  z-index: 50 !important;
  text-align: left;
}

/* Metric data cells */
.pnl-td-metric {
  z-index: 20 !important;
  background: var(--surface) !important;
  text-align: left;
  color: var(--text);
  font-weight: 400;
  padding-left: 16px;
}

.pnl-th-total {
  background: var(--surface-3);
  color: var(--text);
  border-left: 2px solid var(--border);
}

.pnl-table td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 14px;
  text-align: center;
  white-space: nowrap;
  color: var(--text-muted);
}

.pnl-td-metric {
  text-align: left;
  color: var(--text);
  font-weight: 400;
  padding-left: 16px;
}

.pnl-td-total {
  background: var(--surface-2) !important;
  color: var(--text) !important;
  font-weight: 500;
  border-left: 2px solid var(--border);
}

/* Separator rows */
.pnl-sep td {
  padding: 0;
  height: 6px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.pnl-sep .pnl-td-metric { background: var(--surface-2); }

/* Row styles */
.pnl-row-subtotal td { color: var(--text); font-weight: 600; }

.pnl-row-strong td { color: var(--text); font-weight: 600; }

.pnl-row-metric td { color: var(--text-muted); font-size: 12px; }
.pnl-row-metric .pnl-td-metric { color: var(--text-muted); }

.pnl-row-net td {
  color: var(--text);
  font-weight: 600;
}

.pnl-negative { color: #f87171 !important; }
.pnl-positive { color: var(--success) !important; }

/* ── P&L cell selection ─────────────────────────────────────── */
.pnl-selectable {
  cursor: default;
  user-select: none;
}
.pnl-cell-selected {
  background: rgba(59, 130, 246, 0.13) !important;
  outline: 1px solid rgba(59, 130, 246, 0.35);
  outline-offset: -1px;
}

/* ── P&L status bar ─────────────────────────────────────────── */
.pnl-statusbar {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 16px;
  flex: 1;
  padding: 0 24px;
}
.pnl-statusbar.has-data {
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
#funTable .fun-col {
  width: 100px;
  min-width: 100px;
  max-width: 100px;
}
.filter-right {
  display: flex;
  align-items: flex-end;
  border-left: 1px solid var(--border);
  padding-left: 24px;
  gap: 24px;
}
.filter-right .pnl-customise-btn {
  margin-left: 0;
}
/* Remove divider between inputs and Customise/Glossary button on PNL and summary pages */
#tab-pnl .filter-right,
#tab-client-report .filter-right {
  border-left: none;
  padding-left: 0;
}
.filter-right .pnl-statusbar {
  flex: none;
  justify-content: flex-start;
  padding-right: 0;
}
.filter-right .pnl-statusbar.has-data {
  border-right: none;
}
.pnl-status-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.pnl-status-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.pnl-status-value {
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text);
  white-space: nowrap;
}

/* ── Auth overlay ───────────────────────────────────────────── */

/* ── Changes / Planner ──────────────────────────────────────── */
.planner-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.planner-sidebar {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.planner-sidebar-btns {
  display: flex;
  gap: 6px;
  padding: 14px 14px 10px;
}

.planner-new-btn {
  flex: 1;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  text-align: left;
}
.planner-new-btn:hover { opacity: 0.85; }

.planner-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px 16px;
}

.planner-list-empty {
  font-size: 12px;
  color: var(--text-dim);
  padding: 12px;
}

.planner-item {
  padding: 10px 12px 10px 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  border: 1px solid transparent;
  position: relative;
}
.planner-item:hover { background: var(--surface-2); }
.planner-item.active {
  background: var(--accent-dim);
  border-color: rgba(168, 86, 247, 0.2);
}
.planner-item::before {
  content: '⠿';
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: var(--text-dim);
  opacity: 0;
  cursor: grab;
  transition: opacity 0.12s;
}
.planner-item:hover::before { opacity: 1; }
.planner-item.dragging { opacity: 0.4; }
.planner-item.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.planner-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.planner-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.planner-item-date {
  font-size: 11px;
  color: var(--text-muted);
}

.planner-badge {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 20px;
  font-weight: 500;
}
.planner-badge.change  { background: rgba(168, 86, 247, 0.15); color: var(--accent); }
.planner-badge.planned { background: rgba(22, 163, 74, 0.12); color: var(--success); }

.planner-item.planned { background: rgba(22, 163, 74, 0.05); border-color: rgba(22, 163, 74, 0.18); }
.planner-item.planned:hover { background: rgba(22, 163, 74, 0.09); }
.planner-item.planned.active { background: rgba(22, 163, 74, 0.12); border-color: rgba(22, 163, 74, 0.35); }
.planner-item.planned.drag-over { border-color: var(--success); background: rgba(22, 163, 74, 0.12); }

.planner-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.planner-empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 13px;
}

.planner-form {
  display: none;
  flex-direction: column;
  flex: 1;
  padding: 28px 36px;
  gap: 0;
  overflow-y: auto;
}
.planner-form.visible { display: flex; }

.planner-form-heading {
  display: flex;
  align-items: center;
  gap: 8px;
}

.planner-kebab-wrap {
  position: relative;
  flex-shrink: 0;
}
.planner-kebab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
  letter-spacing: 1px;
}
.planner-kebab-btn:hover { background: var(--surface-2); }
.planner-kebab-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  z-index: 200;
  min-width: 140px;
  padding: 4px 0;
}
.planner-kebab-menu.open { display: block; }
.planner-kebab-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 16px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
}
.planner-kebab-item:hover { background: var(--surface-2); }
.planner-kebab-delete { color: #f87171; }
.planner-kebab-delete:hover { background: rgba(248,113,113,0.08); }

.planner-form-top {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.planner-title-input {
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.4px;
  outline: none;
  width: 100%;
}
.planner-title-input::placeholder { color: var(--text-dim); }

.planner-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.planner-meta select { display: none; }

.planner-meta .cr-mob-select-wrap { margin-bottom: 0; }

.planner-body-input {
  flex: 1;
  min-height: 280px;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.75;
  outline: none;
  resize: none;
}
.planner-body-input::placeholder { color: var(--text-dim); }

.planner-form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 20px;
  margin-top: auto;
}

.planner-save-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.planner-save-btn:hover:not(:disabled) { opacity: 0.85; }
.planner-save-btn:disabled {
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: not-allowed;
}

.planner-delete-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 22px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.planner-delete-btn:hover { border-color: #f87171; color: #f87171; }

.planner-save-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ── Budget Tracker ─────────────────────────────────────────── */
.bud-today-text {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 32px;
}

.bud-budget-field {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 32px;
  transition: border-color 0.15s;
}
.bud-budget-field:focus-within { border-color: var(--accent); }

.bud-currency-sym {
  padding: 0 8px;
  font-size: 13px;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
  line-height: 1;
  flex-shrink: 0;
}

.bud-budget-input {
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  padding: 0 10px;
  width: 120px;
  height: 100%;
}
.bud-budget-input::placeholder { color: var(--text-dim); }
.bud-budget-input::-webkit-inner-spin-button,
.bud-budget-input::-webkit-outer-spin-button,
.bud-campaign-amount::-webkit-inner-spin-button,
.bud-campaign-amount::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.bud-budget-input, .bud-campaign-amount { -moz-appearance: textfield; }

.bud-body {
  padding: 24px 32px 40px;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 48px;
}

.bud-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bud-section-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bud-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
  margin: 0;
}

.bud-add-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12px;
  padding: 5px 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.bud-add-btn:hover { border-color: var(--accent); color: var(--accent); }

.bud-table {
  width: 480px;
  border-collapse: collapse;
  font-size: 13px;
}
.bud-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: bottom;
}
.bud-table th:first-child { padding-left: 0; }
.bud-table th:last-child { width: 32px; }

.bud-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.bud-table td:first-child { padding-left: 0; }

.bud-table tbody tr:last-child td { border-bottom: none; }

.bud-table-total td {
  border-top: 1px solid var(--border);
  border-bottom: none;
  padding-top: 10px;
  font-weight: 600;
}

.bud-campaign-name {
  background: none;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  width: 200px;
  padding: 3px 0;
  transition: border-color 0.15s;
}
.bud-campaign-name:focus { border-bottom-color: var(--accent); }
.bud-campaign-name::placeholder { color: var(--text-dim); }

.bud-campaign-amount-cell {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 30px;
  width: 140px;
  transition: border-color 0.15s;
}
.bud-campaign-amount-cell:focus-within { border-color: var(--accent); }
.bud-campaign-amount-cell .bud-currency-sym { border-right: 1px solid var(--border); }

.bud-campaign-amount {
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  padding: 0 8px;
  width: 100%;
  height: 100%;
}
.bud-campaign-amount::placeholder { color: var(--text-dim); }

.bud-platform-select { display: none; }

/* Give the platform cell a positioning context for the dropdown */
#budCampaignBody td:nth-child(2) { position: relative; }

/* Align platform dropdown to match campaign name + amount cell height */
#budCampaignBody .cr-mob-select-wrap    { margin-bottom: 0; }
#budCampaignBody .cr-mob-select-trigger {
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
  display: flex;
  align-items: center;
}

/* Align th label above platform dropdown with the others */
#budCampaignBody td { vertical-align: middle; }

.bud-remove-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 11px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.bud-remove-btn:hover { color: #f87171; background: rgba(248,113,113,0.08); }

.bud-section-breakdown {
  flex: none;
  width: 480px;
}

.bud-section-campaigns {
  flex-shrink: 0;
}

.bud-breakdown-wrap {
  display: flex;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.bud-breakdown-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
  flex: 1;
}

.bud-breakdown-ad-panel {
  background: var(--surface);
  width: 160px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  gap: 12px;
}

.bud-ad-panel-top,
.bud-ad-panel-bottom {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bud-ad-panel-divider {
  height: 1px;
  background: var(--border);
}

.bud-platform-split {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 2px;
}

.bud-plat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.bud-plat-name {
  color: var(--text-muted);
}

.bud-plat-pct {
  color: var(--text);
  font-weight: 500;
}

.bud-breakdown-item {
  background: var(--surface);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bud-breakdown-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.bud-breakdown-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.5px;
}
.bud-breakdown-value.bud-positive { color: #4ade80; }
.bud-breakdown-value.bud-negative { color: #f87171; }

.bud-val-unit {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-left: 2px;
  vertical-align: baseline;
}

/* ── Cohort Analysis ─────────────────────────────────────────── */

.cohort-controls {
  padding: 14px 32px;
  display: flex;
  align-items: center;
  gap: 24px;
  box-sizing: border-box;
}

.cohort-ctrl-divider {
  display: none;
}

.cohort-controls .pnl-customise-btn {
  margin-left: 0;
}

.cohort-controls .pnl-statusbar {
  flex: none;
  justify-content: flex-start;
  padding: 0;
}

.cohort-controls .pnl-statusbar.has-data {
  border-left: 1px solid var(--border);
  border-right: none;
  padding-left: 24px;
}

.pnl-drawer-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

/* Cohort drawer — no divider, X pushed to right, tighter body gap */
#cohortDrawer .pnl-drawer-header {
  border-bottom: none;
  justify-content: space-between;
  padding-bottom: 4px;
}

#cohortDrawer .pnl-drawer-body { padding-top: 4px; }

.cohort-wrap {
  overflow-x: auto;
  overflow-y: auto;
  padding: 0 32px 40px;
  max-height: calc(100vh - 100px);
  scrollbar-width: none;
}

.cohort-wrap::-webkit-scrollbar { display: none; }

.co-table {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
  font-family: var(--font);
  white-space: nowrap;
}


.co-th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  border-bottom: 2px solid var(--border);
  padding: 8px 10px;
  text-align: center;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.co-th.co-fix {
  z-index: 30;
}

.co-mth {
  min-width: 52px;
}

.co-td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 7px 10px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.co-fix {
  position: sticky;
  background: var(--surface);
  z-index: 5;
}

.co-th.co-fix { background: var(--surface-2); z-index: 30; }

.co-fix-last {
  box-shadow: 3px 0 8px rgba(0,0,0,0.08);
  clip-path: inset(0 -12px 0 0);
}

.co-label {
  text-align: center;
  color: var(--text-muted);
  font-weight: 400;
  background: var(--surface);
}

.co-meta {
  background: var(--bg);
}

.co-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 7px 8px;
  text-align: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 52px;
  background: var(--bg);
  color: var(--text-muted);
}

.co-cell.co-cell-empty {
  border: none;
  background: var(--bg);
}


.cohort-empty {
  padding: 48px 32px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Forecasting Tab ─────────────────────────────────────────── */

#tab-forecasting .pnl-filters {
  border-bottom: none;
}

.fcast-body {
  display: flex;
  flex-direction: row;
  gap: 28px;
  padding: 0 32px 40px;
}

.fcast-col {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Table wrapper — fixed to match table width ── */
.fcast-wrap {
  width: 241px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* ── Table fixed layout — columns never shift with value changes ── */
.fcast-table {
  width: 241px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
  font-family: var(--font);
}

.fcast-td-lbl {
  width: 125px;
  padding: 9px 16px;
  color: var(--text-muted);
  font-weight: 400;
  font-size: 12px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.fcast-td-val {
  width: 114px;
  padding: 9px 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  white-space: nowrap;
}

.fcast-table tr:last-child .fcast-td-lbl,
.fcast-table tr:last-child .fcast-td-val {
  border-bottom: none;
}

/* ── Header ── */
.fcast-th-color {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.2px;
  padding: 9px 16px;
  text-align: center;
  border-bottom: 2px solid var(--border);
}

/* Separator rows */
.fcast-sep td {
  padding: 0;
  height: 5px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

/* Profit % cell colours */
.fcast-val-green { background: rgba(74, 222, 128, 0.12) !important; color: #16a34a !important; }
.fcast-val-red   { background: rgba(248, 113, 113, 0.12) !important; color: #dc2626 !important; }

/* Hidden first row that locks column widths for table-layout: fixed */
.fcast-col-sizer th {
  height: 0;
  padding: 0;
  border: none;
  overflow: hidden;
  line-height: 0;
  font-size: 0;
}
.fcast-th-sizer-lbl { width: 125px; }
.fcast-th-sizer-val { width: 116px; }

/* ── Input cells ── */
.fcast-td-val--inp {
  padding: 0 !important;
  background: var(--surface) !important;
  color: var(--text) !important;
}

.fcast-input-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 3px 10px;
}

.fcast-inp-pre,
.fcast-inp-suf {
  font-size: 12px;
  color: var(--text-muted);
  user-select: none;
  flex-shrink: 0;
}

.fcast-inp {
  width: 52px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  text-align: center;
  padding: 3px 2px;
  outline: none;
  -moz-appearance: textfield;
}

.fcast-inp::-webkit-inner-spin-button,
.fcast-inp::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.fcast-inp::placeholder { color: var(--text-dim); }

/* ── Scrollbars ─────────────────────────────────────────────── */
/* Horizontal scrollbar only — vertical bars hidden throughout */
::-webkit-scrollbar { width: 0; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface-2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Client Report ───────────────────────────────────────────── */
.cr-chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 10% 16px 28px;
}

.cr-chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px 10px;
}

/* Native select hidden — replaced by custom dropdown everywhere */
.cr-metric-select { display: none !important; }

/* ── Custom metric dropdown ─────────────────────────────────── */
.cr-mob-select-wrap {
  position: relative;
  margin-bottom: 10px;
}

.cr-mob-select-trigger {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 8px;
  cursor: pointer;
  white-space: nowrap;
  text-align: left;
  transition: border-color 0.15s;
}

.cr-mob-select-trigger:hover { border-color: var(--accent); }

.cr-mob-select-trigger svg {
  width: 14px; height: 14px;
  flex-shrink: 0;
  color: var(--text-dim);
}

.cr-mob-select-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.13);
  z-index: 300;
  min-width: 180px;
  max-height: 26vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.cr-mob-select-list.open { display: block; }

.cr-mob-search-wrap {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  position: relative;
  display: flex;
  align-items: center;
}

.cr-mob-search {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 12.5px;
  padding: 6px 28px 6px 10px;
  outline: none;
  transition: border-color 0.15s;
}

.cr-mob-search:focus { border-color: var(--accent); background: var(--surface); }
.cr-mob-search::placeholder { color: var(--text-dim); }

.cr-mob-search-clear {
  display: none;
  position: absolute;
  right: 17px;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  background: var(--surface-3);
  border-radius: 50%;
  cursor: pointer;
  font-size: 9px;
  color: var(--text-dim);
  line-height: 1;
  padding: 0;
  transition: background 0.12s, color 0.12s;
}

.cr-mob-search-clear.visible { display: flex; }
.cr-mob-search-clear:hover { background: var(--border); color: var(--text); }

.cr-mob-select-item {
  display: block;
  width: 100%;
  padding: 9px 14px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
}

.cr-mob-select-item:last-child { border-bottom: none; }
.cr-mob-select-item:hover { background: var(--surface-2); }

.cr-mob-select-item.selected {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-dim);
}

.cr-mob-select-item.hidden { display: none; }

.cr-chart-wrap {
  position: relative;
  height: 160px;
}
.cr-chart-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

/* ── Summary page Glossary modal ────────────────────────────────────────── */
.cr-glos-overlay {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.45); backdrop-filter: blur(3px);
  align-items: center; justify-content: center; padding: 24px;
}
.cr-glos-overlay.open { display: flex; }
.cr-glos-modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 24px 64px rgba(0,0,0,.18);
  width: 100%; max-width: 860px; height: 88vh; max-height: 88vh;
  display: flex; flex-direction: column;
}
.cr-glos-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 18px 22px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.cr-glos-head-left { display: flex; flex-direction: column; gap: 2px; }
.cr-glos-head-title { font-size: 14px; font-weight: 700; color: var(--text); }
.cr-glos-head-sub { font-size: 11.5px; color: var(--text-dim); }
.cr-glos-close {
  background: none; border: none; cursor: pointer; color: var(--text-dim);
  font-size: 18px; line-height: 1; padding: 2px 4px; border-radius: 4px;
  transition: color .12s; flex-shrink: 0;
}
.cr-glos-close:hover { color: var(--text-muted); }
.cr-glos-body { display: flex; flex: 1; min-height: 0; overflow: hidden; }
.cr-glos-left {
  width: 172px; flex-shrink: 0; border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.cr-glos-search-wrap {
  padding: 8px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
  position: relative; display: flex; align-items: center;
}
.cr-glos-search-icon {
  position: absolute; left: 18px; top: 50%; transform: translateY(-50%);
  color: var(--text-dim); width: 13px; height: 13px; pointer-events: none; flex-shrink: 0;
}
.cr-glos-search {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px;
  padding: 6px 26px 6px 30px; font-family: var(--font); font-size: 12.5px;
  outline: none; color: var(--text);
}
.cr-glos-search::placeholder { color: var(--text-dim); }
.cr-glos-search:focus { border-color: var(--accent); }
.cr-glos-search-clear {
  display: none; position: absolute; right: 17px; width: 15px; height: 15px;
  background: var(--border); border: none; border-radius: 50%;
  font-size: 8px; color: var(--text-muted); cursor: pointer;
  align-items: center; justify-content: center; transition: background .1s;
}
.cr-glos-search-clear.visible { display: flex; }
.cr-glos-search-clear:hover { background: var(--surface-3); }
.cr-glos-items {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: none; -ms-overflow-style: none;
}
.cr-glos-items::-webkit-scrollbar { display: none; }
.cr-glos-metric-item {
  display: block; width: 100%; padding: 9px 14px;
  border-bottom: 1px solid var(--surface-3);
  font-size: 12.5px; color: var(--text-muted); font-weight: 500;
  cursor: pointer; background: none; border-left: none; border-right: none; border-top: none;
  text-align: left; transition: background .1s, color .1s;
}
.cr-glos-metric-item:last-child { border-bottom: none; }
.cr-glos-metric-item:hover { background: var(--surface-2); color: var(--text); }
.cr-glos-metric-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.cr-glos-right { flex: 1; overflow-y: auto; padding: 28px 30px; min-width: 0; }
.cr-glos-metric-label { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.cr-glos-metric-category {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--accent); background: var(--accent-dim);
  padding: 2px 9px; border-radius: 100px; margin-bottom: 18px;
}
.cr-glos-metric-desc { font-size: 13.5px; color: var(--text-muted); line-height: 1.8; margin-bottom: 18px; }
.cr-glos-metric-formula {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 11px 14px; font-size: 12.5px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.6;
}
.cr-glos-metric-formula strong { color: var(--text); font-weight: 600; }
.cr-glos-metric-tip {
  display: flex; gap: 10px; align-items: flex-start;
  background: rgba(168,86,247,.06); border: 1px solid rgba(168,86,247,.2);
  border-radius: 6px; padding: 11px 14px; font-size: 12.5px; color: var(--text-muted); line-height: 1.7;
}
.cr-glos-metric-tip svg { flex-shrink: 0; margin-top: 2px; color: var(--accent); width: 14px; height: 14px; }
.cr-glos-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; text-align: center; color: var(--text-dim); gap: 12px; padding: 40px 24px;
}
.cr-glos-empty svg { width: 40px; height: 40px; opacity: .3; }
.cr-glos-empty p { font-size: 13px; max-width: 240px; line-height: 1.6; }
.cr-glos-empty-mobile { display: none; }

/* ── Summary page: remove filter bar divider and match PNL gap on desktop ── */
@media (min-width: 769px) {
  #crFilters.pnl-filters { border-bottom: none; }
  .cr-chart-grid { padding-top: 0; }
}

/* ── Mobile — Summary page only ─────────────────────────────── */
@media (max-width: 768px) {

  /* Remove blue tap highlight on all elements */
  * { -webkit-tap-highlight-color: transparent; }

  /* Hide sticky header bar entirely */
  .app-header { display: none !important; }

  /* Remove header offset — content starts at top */
  .app-body {
    margin-top: 0;
    height: 100vh;
    overflow: auto;
  }

  /* Allow body/html to scroll on mobile */
  html, body { overflow: auto; }

  /* Hide sidebar toggle + sidebar entirely */
  .sidebar-toggle { display: none !important; }
  .sidebar        { display: none !important; }

  /* Let main content fill the full width */
  .main-content { overflow-y: auto; }

  /* Force only the Summary tab visible */
  .tab-panel             { display: none !important; }
  #tab-client-report     { display: flex !important; height: auto; }

  /* ── Summary filters: compact, no labels ────────────────────── */
  #crFilters.pnl-filters { border-bottom: none; }
  #crFilters.pnl-filters {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 14px 0;
  }

  /* Hide all filter labels */
  #crFilters .pnl-filter-label { display: none; }

  /* Date range spans full width on its own row */
  #crFilters .pnl-filter-group:nth-child(1) { width: 100%; }

  /* Group by + Customers share the second row */
  #crFilters .pnl-filter-group:nth-child(2),
  #crFilters .pnl-filter-group:nth-child(3) { flex: 0 0 auto; }

  /* Compact date inputs */
  #crFilters .pnl-date-row { gap: 6px; }
  #crFilters .pnl-date-input {
    font-size: 11px;
    padding: 6px 28px 6px 8px;
    width: 112px;
  }

  /* Smaller seg buttons */
  #crFilters .seg-btn {
    font-size: 11px;
    padding: 5px 9px;
  }

  /* Glossary button joins the Group by / Customers row */
  #crFilters .filter-right {
    flex: 0 0 auto;
    align-items: center;
    border-left: none;
    padding-left: 0;
  }
  #crFilters .filter-right .pnl-customise-btn {
    font-size: 11px;
    padding: 5px 9px;
  }

  /* ── Custom metric dropdown — mobile size overrides ─────────── */
  .cr-mob-select-wrap  { margin-bottom: 6px; }
  .cr-mob-select-trigger { font-size: 11px; padding: 5px 9px; }
  .cr-mob-select-trigger svg { width: 12px; height: 12px; }
  .cr-mob-select-list { -webkit-overflow-scrolling: touch; max-height: 23vh; }
  .cr-mob-search { font-size: 11px; }
  .cr-mob-select-item { font-size: 11px; }

  /* ── Summary charts: single column on mobile ─────────────────── */
  .cr-chart-grid {
    grid-template-columns: 1fr;
    padding: 10px 14px 16px;
    gap: 10px;
  }

  .cr-chart-wrap { height: 180px; }

  /* ── Glossary modal — mobile ─────────────────────────────────── */
  .cr-glos-modal { max-height: 95vh; border-radius: 10px; max-width: 100%; }
  .cr-glos-body { flex-direction: column; }
  .cr-glos-left { width: 100%; flex-shrink: 0; border-right: none; border-bottom: 1px solid var(--border); max-height: 260px; }
  .cr-glos-right { flex: 1; overflow-y: auto; padding: 18px 18px 24px; min-height: 0; }
  .cr-glos-metric-label { font-size: 14px; }
  .cr-glos-metric-item { font-size: 11.5px; }
  .cr-glos-search { font-size: 11.5px; }
  .cr-glos-metric-desc { font-size: 11.5px; }
  .cr-glos-metric-formula { font-size: 11.5px; }
  .cr-glos-metric-tip { font-size: 11.5px; }
  .cr-glos-empty p { font-size: 11.5px; }
  .cr-glos-empty { padding: 24px 16px; }
  .cr-glos-empty-desktop { display: none; }
  .cr-glos-empty-mobile { display: block; }
}
