/* Shared design tokens and layout — used by all dashboard pages */

:root {
  --font-body: 'Inter', sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 20px;
  --text-2xl: 26px;
  --text-3xl: 32px;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;

  --bg-base: #f5f5f7;
  --bg-surface: #FFFFFF;
  --bg-elevated: #FFFFFF;
  --bg-subtle: #f0f0f3;
  --bg-hover: #eaeaee;

  --border-subtle: #e3e3e9;
  --border-default: #d5d5dc;
  --border-strong: #aeaeb8;

  --text-primary: #1a1a1f;
  --text-secondary: #494950;
  --text-tertiary: #87878f;
  --text-label: #6a6a72;
  --text-disabled: #b6b6bf;

  --accent: #3b6ef5;
  --accent-hover: #2a5ce6;
  --accent-subtle: #eef2fe;

  --status-active: #16A34A;
  --status-paused: #CA8A04;
  --negative: #DC2626;

  --white: var(--bg-surface);
  --off: var(--bg-subtle);
  --ink: var(--text-primary);
  --ink-2: var(--text-secondary);
  --ink-3: var(--text-tertiary);
  --ink-4: var(--text-disabled);
  --border: var(--border-default);
  --green: var(--status-active);
  --red: var(--negative);
  --amber: var(--status-paused);
  --blue: var(--accent);
  --tag: var(--bg-hover);
  --radius: 10px;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px;

  --positive: var(--status-active);
  --neutral: var(--text-tertiary);
  --status-removed: var(--negative);
  --chart-cost: #3B82F6;
  --chart-green: #34D399;
  --chart-weekends: var(--chart-secondary);
  --chart-secondary: #818cf8;
  --bg-insight: var(--bg-subtle);

  --crosshatch-stroke: var(--border-strong);
  --crosshatch-border: var(--border-default);
  --crosshatch-label: var(--text-tertiary);

  --sidebar-width: 260px;
  --sidebar-collapsed-width: 60px;
}

* { box-sizing: border-box; transition-timing-function: cubic-bezier(0.4,0,0.2,1); }
*:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-subtle), 0 0 0 1px var(--accent); }
body { margin: 0; font-family: var(--font-body); background: var(--bg-base); color: var(--text-primary); min-height: 100vh; line-height: 1.4; font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; height: 100vh;
  width: var(--sidebar-width);
  background: #1a1a1a;
  border-right: 1px solid #2d2d2d;
  display: flex; flex-direction: column;
  z-index: 200; overflow-x: hidden; overflow-y: auto;
  transition: width 250ms cubic-bezier(0.4,0,0.2,1);
  box-shadow: 1px 0 0 #2d2d2d;
}
body.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-width); }
.main-content { margin-left: var(--sidebar-width); min-height: 100vh; transition: margin-left 250ms cubic-bezier(0.4,0,0.2,1); }
body.sidebar-collapsed .main-content { margin-left: var(--sidebar-collapsed-width); }

/* ── Main content layout ─────────────────────────────────────────── */
.container { max-width: 1400px; margin: 0 auto; padding: 28px 32px; }
.container--full { max-width: none; margin: 0; }
.page-header { margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--border-subtle); }
.page-header--flex { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: var(--text-3xl); font-weight: 700; margin: 0 0 4px 0; color: var(--ink); letter-spacing: -0.5px; }
.page-header p { font-size: var(--text-md); color: var(--ink-3); margin: 0; }

/* Date controls — pill-style date picker for panel/page headers */
.date-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding-top: 2px;
}
.date-picker-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-default);
  border-radius: 8px;
  padding: 7px 4px 7px 12px;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.date-picker-pill:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}
.date-picker-icon {
  width: 18px;
  height: 18px;
  color: var(--accent);
  flex-shrink: 0;
}
.date-picker-pill .select-wrapper select {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-primary);
  padding: 0 22px 0 4px;
  border: none;
  background: transparent;
  min-width: 120px;
  cursor: pointer;
}
.date-picker-pill .select-wrapper select:focus {
  box-shadow: none;
}
.date-picker-pill .select-wrapper::after {
  right: 6px;
  border-top-color: var(--accent);
}
.date-controls input[type="date"] {
  font-size: var(--text-base);
  font-weight: 500;
  padding: 7px 10px;
  border: 1.5px solid var(--border-default);
  border-radius: 8px;
}
.date-controls input[type="date"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}
.date-controls .toggle-label {
  font-size: var(--text-base);
  font-weight: 500;
}
.date-controls .compare-period-label {
  font-size: var(--text-sm);
  color: var(--ink-3);
  white-space: nowrap;
}

.sidebar-header { position: relative; display: flex; align-items: center; gap: 10px; padding: 14px 12px; border-bottom: 1px solid #2d2d2d; flex-shrink: 0; min-height: 60px; }
.sidebar-logo-icon { flex-shrink: 0; }
.sidebar-title-text { font-size: var(--text-lg); font-weight: 700; color: #e8e6e0; white-space: normal; overflow: hidden; line-height: 1; opacity: 1; max-width: 160px; transition: opacity 220ms ease, max-width 250ms cubic-bezier(0.4,0,0.2,1); letter-spacing: -0.1px; margin-top: -1px; }
body.sidebar-collapsed .sidebar-title-text { opacity: 0; max-width: 0; }

.sidebar-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border-radius: 7px; background: transparent; border: 1px solid transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #918f8a; padding: 0; flex-shrink: 0; transition: background 220ms ease, border-color 220ms ease, color 220ms ease; }
.sidebar-toggle:hover { background: #2a2a2a; border-color: #3a3a3a; color: #e8e6e0; }
.sidebar-toggle svg { transition: transform 250ms cubic-bezier(0.4,0,0.2,1); }
body.sidebar-collapsed .sidebar-toggle svg { transform: scaleX(-1); }

.sidebar-controls { padding: 10px 10px 8px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid #2d2d2d; flex-shrink: 0; overflow: hidden; max-height: 600px; opacity: 1; transition: max-height 250ms cubic-bezier(0.4,0,0.2,1), opacity 220ms ease, padding 250ms ease; }
body.sidebar-collapsed .sidebar-controls { max-height: 0; opacity: 0; padding-top: 0; padding-bottom: 0; pointer-events: none; }
.sidebar-control-label { display: block; font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: #918f8a; margin-bottom: 3px; }
.sidebar-controls .select-wrapper { width: 100%; }
.sidebar-controls .select-wrapper select { min-width: 0; width: 100%; font-size: var(--text-sm); padding: 7px 24px 7px 8px; background: #252525; border-color: #3a3a3a; color: #e8e6e0; }
.sidebar-controls .select-wrapper::after { border-top-color: #918f8a; }
.sidebar-controls input[type="date"] { width: 100%; min-width: 0; font-size: var(--text-sm); padding: 7px 8px; background: #252525; border-color: #3a3a3a; color: #e8e6e0; }

.sidebar-page-title { padding: 14px 12px 10px; flex-shrink: 0; }
.sidebar-page-title h2 { font-size: var(--text-sm); font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: #918f8a; margin: 0; white-space: nowrap; overflow: hidden; opacity: 1; transition: opacity 220ms ease; }
body.sidebar-collapsed .sidebar-page-title h2 { opacity: 0; }

.sidebar-divider { height: 1px; background: #2d2d2d; flex-shrink: 0; margin: 2px 0; }
.sidebar-section-label { padding: 14px 14px 4px; font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: #5a5a55; flex-shrink: 0; white-space: nowrap; overflow: hidden; opacity: 1; transition: opacity 220ms ease, max-height 220ms ease, padding 220ms ease; }
body.sidebar-collapsed .sidebar-section-label { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; overflow: hidden; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 6px 8px; flex-shrink: 0; overflow: hidden; }
.sidebar-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; color: #c0bdb8; font-size: var(--text-base); font-weight: 500; cursor: pointer; background: none; border: none; width: 100%; text-align: left; text-decoration: none; font-family: var(--font-body); transition: background 220ms ease, color 220ms ease; white-space: nowrap; min-height: 36px; line-height: 1.3; position: relative; }
.sidebar-item:link, .sidebar-item:visited { color: #c0bdb8; }
.sidebar-item:hover { background: #252525; color: #e8e6e0; }
.sidebar-item.active { background: rgba(59, 110, 245, 0.12); color: #fff; font-weight: 600; }
.sidebar-item.active::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--accent); }
.sidebar-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.5; transition: opacity 220ms ease; }
.sidebar-item.active .sidebar-icon { opacity: 1; }
.sidebar-item:hover .sidebar-icon { opacity: 0.8; }
.sidebar-item-label { white-space: nowrap; overflow: hidden; opacity: 1; max-width: 160px; transition: opacity 220ms ease, max-width 250ms cubic-bezier(0.4,0,0.2,1); }
body.sidebar-collapsed .sidebar-item-label { opacity: 0; max-width: 0; }
a.sidebar-item:not(.active)::after {
  content: '↗';
  font-size: var(--text-xs);
  opacity: 0;
  margin-left: auto;
  flex-shrink: 0;
  transition: opacity 220ms ease;
}
a.sidebar-item:not(.active):hover::after { opacity: 0.5; }
body.sidebar-collapsed a.sidebar-item::after { display: none; }
.sidebar-spacer { flex: 1; min-height: 12px; }
.sidebar-bottom { padding: 4px 6px 10px; display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.sidebar-bottom .sidebar-item { color: #c0bdb8; font-size: var(--text-base); }
.sidebar-bottom .sidebar-item:hover { color: #e8e6e0; background: #252525; }

.sidebar-sub-nav { display: flex; flex-direction: column; gap: 2px; padding: 2px 6px 6px 22px; overflow: hidden; }
body.sidebar-collapsed .sidebar-sub-nav { display: none; }
.sidebar-sub-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; border-radius: 7px; color: #a0a09a; font-size: var(--text-sm); font-weight: 500; text-decoration: none; font-family: var(--font-body); transition: background 220ms ease, color 220ms ease; white-space: nowrap; min-height: 32px; line-height: 1.3; position: relative; background: none; border: none; width: 100%; text-align: left; cursor: pointer; }
.sidebar-sub-item::before { content: ''; position: absolute; left: 5px; top: 50%; width: 5px; height: 1px; background: #4a4a46; }
.sidebar-sub-item:hover { background: #252525; color: #e8e6e0; }
.sidebar-sub-item.active { background: rgba(59, 110, 245, 0.12); color: #fff; font-weight: 600; }
.sidebar-sub-item.active::after { content: ''; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 2px; background: var(--accent); }
.sidebar-sub-item.active::before { background: rgba(255,255,255,0.4); }
.sidebar-sub-item-label { white-space: nowrap; overflow: hidden; opacity: 1; max-width: 150px; transition: opacity 220ms ease, max-width 250ms cubic-bezier(0.4,0,0.2,1); }
body.sidebar-collapsed .sidebar-sub-item-label { opacity: 0; max-width: 0; }
a.sidebar-sub-item:not(.active)::after {
  content: '↗';
  font-size: var(--text-xs);
  opacity: 0;
  margin-left: auto;
  flex-shrink: 0;
  transition: opacity 220ms ease;
}
a.sidebar-sub-item:not(.active):hover::after { opacity: 0.5; }
body.sidebar-collapsed a.sidebar-sub-item::after { display: none; }

.sidebar-placeholder { padding: 20px 14px; color: #918f8a; font-size: var(--text-base); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Button ──────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px; border: none; font-family: var(--font-body); font-size: var(--text-base); font-weight: 600; cursor: pointer; transition: background 200ms ease, opacity 200ms ease; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Toolbar ─────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.last-updated { font-size: var(--text-sm); color: var(--ink-3); margin-left: auto; }

/* ── Utility ────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Section cards ──────────────────────────────────────────── */
.section { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius); overflow: hidden; }
.section-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border-subtle); }
.section-title { font-size: var(--text-lg); font-weight: 600; color: var(--ink); margin: 0 0 4px 0; }
.section-desc { font-size: var(--text-base); color: var(--ink-2); margin: 0 0 8px 0; line-height: 1.45; }
.section-note { font-size: var(--text-sm); color: var(--ink-3); margin: 0; line-height: 1.4; }

/* ── Loading / error states ──────────────────────────────────── */
.loading-state, .loading { text-align: center; padding: 48px 24px; color: var(--ink-3); }
.loading-spinner { display: inline-block; width: 28px; height: 28px; border: 3px solid var(--border-subtle); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; margin-bottom: 14px; }
.loading-state p, .loading p { font-size: var(--text-md); margin: 0; }
.error-box { padding: 14px 18px; background: #fef2f2; border: 1px solid #fecaca; border-radius: var(--radius); color: #b91c1c; font-size: var(--text-base); margin-bottom: 24px; }
.empty-state { text-align: center; padding: 48px 24px; color: var(--ink-3); font-size: var(--text-md); }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 400; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: 12px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18); }
.modal--sm { max-width: 360px; }
.modal--lg { max-width: 640px; }
.modal--xl { max-width: 920px; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 20px 24px 16px; border-bottom: 1px solid var(--border-subtle); }
.modal-header h2 { font-size: var(--text-xl); font-weight: 700; color: var(--ink); margin: 0; }
.modal-header p { font-size: var(--text-base); color: var(--ink-3); margin: 4px 0 0; }
.modal-close { background: none; border: none; color: var(--ink-3); font-size: var(--text-xl); cursor: pointer; padding: 0 0 0 12px; line-height: 1; flex-shrink: 0; transition: color 150ms ease; }
.modal-close:hover { color: var(--ink); }
.modal-body { padding: 20px 24px; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 14px 24px 20px; border-top: 1px solid var(--border-subtle); }
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }
.form-group label { display: block; font-size: var(--text-sm); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); margin-bottom: 5px; }
.form-group input, .form-group textarea, .form-group select { width: 100%; box-sizing: border-box; padding: 8px 12px; border: 1px solid var(--border-default); border-radius: 8px; background: var(--bg-surface); color: var(--text-primary); font-size: var(--text-md); font-family: var(--font-body); outline: none; transition: border-color 220ms ease, box-shadow 220ms ease; }
.form-group input:focus, .form-group textarea:focus, .form-group select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.form-group textarea { resize: vertical; min-height: 80px; }

/* ── Table wrapper ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; overflow-y: auto; max-height: calc(100vh - 260px); }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.table-wrap thead th { background: var(--bg-subtle); padding: 12px 14px; text-align: left; font-size: var(--text-sm); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-label); border-bottom: 1px solid var(--border-subtle); white-space: nowrap; position: sticky; top: 0; z-index: 2; }
.table-wrap thead th.num { text-align: right; }
.table-wrap tbody tr { border-bottom: 1px solid var(--border-subtle); transition: background 150ms ease; }
.table-wrap tbody tr:last-child { border-bottom: none; }
.table-wrap tbody tr:hover td { background: var(--bg-hover); }
.table-wrap tbody td { padding: 12px 14px; color: var(--ink); vertical-align: middle; }
.table-wrap tbody td.num { text-align: right; font-variant-numeric: tabular-nums; font-size: var(--text-sm); }

/* ── Stat cards ─────────────────────────────────────────────── */
.stat-cards { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 24px; }
.stat-card {
  flex: 1;
  min-width: 140px;
  padding: var(--space-5) var(--space-6);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
}
.stat-card__value {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}
.stat-card__value--text {
  font-family: var(--font-body);
  font-size: var(--text-lg);
}
.stat-card__label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-top: 6px;
}
.stat-card--wide { min-width: 200px; }
.stat-card--wide .stat-card__value { word-break: break-word; }
.stat-card--critical .stat-card__value { color: var(--negative); }
.stat-card--warning .stat-card__value { color: var(--status-paused); }
.stat-card--ok .stat-card__value { color: var(--status-active); }
.stat-card--info .stat-card__value { color: var(--accent); }

/* ── Shared form controls ────────────────────────────────────── */
.select-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.select-wrapper::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--text-tertiary);
  pointer-events: none;
}
.select-wrapper select {
  appearance: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 7px;
  padding: 7px 28px 7px 10px;
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 220ms ease;
  min-width: 200px;
}
.select-wrapper select:hover { border-color: var(--border-strong); }
.select-wrapper select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  padding: 6px 14px;
  border-radius: 7px;
  border: 1px solid var(--border-default);
  cursor: pointer;
  font-family: var(--font-body);
  transition: background 220ms ease, border-color 220ms ease;
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

/* ── Multi-filter system ─────────────────────────────────────── */
.mf-filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) 0;
}
.mf-filters:empty, .mf-filters:not(:has(.mf-row)) { padding: 0; }
.mf-filters:not(:has(.mf-row)) .mf-add { margin-top: 0; }
.mf-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.mf-row .select-wrapper select { min-width: 140px; }
.mf-row .mf-val {
  width: 120px;
  padding: 6px 10px;
  border: 1px solid var(--border-default);
  border-radius: 7px;
  font-family: var(--font-body);
  font-size: var(--text-base);
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: border-color 220ms ease;
}
.mf-row .mf-val:hover { border-color: var(--border-strong); }
.mf-row .mf-val:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
  outline: none;
}
.mf-remove {
  background: none;
  border: 1px solid transparent;
  color: var(--text-tertiary);
  font-size: var(--text-lg);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 150ms ease, background 150ms ease;
}
.mf-remove:hover {
  color: var(--negative);
  background: rgba(220, 38, 38, 0.08);
}
.mf-add {
  align-self: flex-start;
  font-size: var(--text-sm);
  padding: 4px 12px;
}
