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

:root {
  --navy: #19223F;
  --dark: #0d1117;
  --dark2: #0a0e1a;
  --gold: #C99E50;
  --tan: #EBCA9C;
  --slate: #7FA8C9;
  --border: rgba(255,255,255,0.06);
  --text: #d0d8e4;
  --text-dim: #8893A0;
  --sidebar-w: 280px;
  --header-h: 48px;
  --stats-h: 68px;
  --tab-h: 42px;
  --font: 'Lato', -apple-system, sans-serif;
  --font-head: 'Noto Sans Display', 'Lato', sans-serif;
}

html, body {
  height: 100%;
  background: var(--dark2);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Mobile Bar ── */
#mobile-bar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--dark);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 100;
}

.mobile-logo { height: 24px; width: auto; }

.mobile-actions { display: flex; gap: 6px; }

.mobile-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.mobile-btn:hover { background: rgba(255,255,255,0.08); }

/* ── App Layout ── */
#app-layout {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--dark);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 50;
  flex-shrink: 0;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.sidebar-header {
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-logo { height: 28px; width: auto; }

.sidebar-header .subtitle {
  font-size: 11px;
  color: var(--tan);
  font-weight: 400;
  letter-spacing: 0.5px;
  flex: 1;
}

.sidebar-close-btn { display: none; }

/* Sidebar sections */
.sidebar-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
  font-size: 10px;
  font-weight: 600;
  color: var(--tan);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

/* Collapsible */
h3.collapsible {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

h3.collapsible::before {
  content: '';
  display: inline-block;
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--tan);
  transition: transform 0.2s;
  flex-shrink: 0;
}

h3.collapsible.collapsed::before { transform: rotate(-90deg); }

.collapsible-content {
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.collapsible-content.collapsed {
  max-height: 0 !important;
}

/* Sidebar inputs */
.sidebar-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
  color: #fff;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  font-family: var(--font);
}
.sidebar-input:focus { border-color: rgba(127,168,201,0.5); }
.sidebar-input::placeholder { color: rgba(176,184,196,0.4); }

/* Date inputs */
.date-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.date-label {
  font-size: 11px;
  color: var(--text-dim);
  width: 30px;
  flex-shrink: 0;
}
.sidebar-date {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 5px;
  background: rgba(255,255,255,0.04);
  color: #fff;
  font-size: 12px;
  outline: none;
  font-family: var(--font);
}
.sidebar-date:focus { border-color: rgba(127,168,201,0.5); }

.preset-btns {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}
.preset-btn {
  flex: 1;
  padding: 5px 2px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 4px;
  background: rgba(255,255,255,0.04);
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}
.preset-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.preset-btn.active { background: rgba(201,158,80,0.15); border-color: var(--gold); color: var(--gold); }

/* Filter items */
.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  cursor: pointer;
  font-size: 12px;
  color: #aab;
  transition: color 0.1s;
}
.filter-item:hover { color: #fff; }
.filter-item input[type="checkbox"] { accent-color: var(--slate); flex-shrink: 0; }
.filter-toggle-all {
  font-size: 11px;
  color: var(--slate);
  cursor: pointer;
  margin-bottom: 6px;
  display: inline-block;
}
.filter-toggle-all:hover { color: #A4C4DE; }

/* Toggle */
.sidebar-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  cursor: pointer;
  color: #aab;
  font-size: 12px;
}
.sidebar-toggle input { accent-color: var(--slate); }

/* Actions */
.sidebar-actions { display: flex; flex-direction: column; gap: 8px; }

.action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
  font-family: var(--font);
}
.action-btn:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.2); }
.action-btn:active { transform: scale(0.98); }
.action-btn.loading { opacity: 0.6; pointer-events: none; }

.cache-info {
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
}

/* ── Sidebar overlay ── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
}
#sidebar-overlay.visible { display: block; }

/* ── Main Content ── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Stats Bar */
#stats-bar {
  display: flex;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.stat-card {
  flex: 1;
  padding: 12px 16px;
  background: var(--dark);
  text-align: center;
}

.stat-value {
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 600;
  color: var(--tan);
  line-height: 1.2;
}

.stat-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-top: 2px;
}

/* Tab Nav */
#tab-nav {
  display: flex;
  background: var(--dark);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  flex-shrink: 0;
}

.tab {
  padding: 11px 16px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }

/* Tab panels */
.tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.tab-panel.active { display: block; }

/* Loading / Error */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  padding: 20px;
  color: #f87171;
  background: rgba(248,113,113,0.08);
  border-radius: 8px;
  margin: 16px;
  font-size: 13px;
}

/* ── Jobs Toolbar ── */
#jobs-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.sort-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.sort-select {
  background: var(--dark);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  outline: none;
}
.sort-select:focus { border-color: var(--gold); }

/* ── Outlier Badge ── */
.outlier-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  background: rgba(248,113,113,0.15);
  color: #f87171;
  border: 1px solid rgba(248,113,113,0.3);
}

/* ── Job Cards ── */
.job-card-wrapper { margin-bottom: 8px; }

.job-card {
  background: var(--dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.job-card:hover { border-color: rgba(255,255,255,0.12); background: rgba(255,255,255,0.02); }
.job-card-wrapper.expanded .job-card { border-radius: 8px 8px 0 0; border-bottom-color: transparent; }

.job-card-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.job-num {
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 600;
  color: var(--tan);
  white-space: nowrap;
}

.job-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  line-height: 1.3;
  min-width: 0;
}

.status-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

.job-card-metrics {
  display: flex;
  gap: 20px;
  margin-bottom: 10px;
}

.metric { display: flex; flex-direction: column; gap: 2px; }
.metric-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}
.metric-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric-value.good { color: #4ade80; }
.metric-value.warn { color: var(--gold); }
.metric-value.no-price { color: var(--text-dim); }

/* Person bar */
.person-bar-wrap {
  display: flex;
  height: 14px;
  border-radius: 3px;
  overflow: hidden;
  background: rgba(255,255,255,0.04);
}

.person-bar-seg {
  height: 100%;
  transition: opacity 0.15s;
  position: relative;
}
.person-bar-seg:hover { opacity: 0.8; }

/* Job detail (expandable) */
.job-detail {
  display: none;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
}
.job-card-wrapper.expanded .job-detail { display: block; }

.detail-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.detail-section:last-child { border-bottom: none; }

.detail-section-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--tan);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}

.detail-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.detail-row:last-child { border-bottom: none; }

.detail-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.detail-name { flex: 1; color: var(--text); }
.detail-val { color: var(--text-dim); }
.detail-val-em { color: var(--tan); font-weight: 600; }
.detail-pct { color: var(--text-dim); width: 36px; text-align: right; }
.detail-hrs { width: 48px; text-align: right; color: var(--text); }

/* ── Person Cards ── */
.person-card-wrapper { margin-bottom: 8px; }

.person-card {
  background: var(--dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s;
  user-select: none;
}
.person-card:hover { border-color: rgba(255,255,255,0.12); }
.person-card-wrapper.expanded .person-card { border-radius: 8px 8px 0 0; border-bottom-color: transparent; }

.person-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.person-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--dark);
  flex-shrink: 0;
}

.person-card-info { flex: 1; }
.person-card-name { font-size: 14px; font-weight: 600; color: var(--text); }
.person-card-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.person-card-metrics {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.person-detail {
  display: none;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
}
.person-card-wrapper.expanded .person-detail { display: block; }

/* ── Summary Charts ── */
.chart-section {
  background: var(--dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.chart-title {
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 600;
  color: var(--tan);
  margin-bottom: 14px;
}

/* Horizontal bar charts */
.h-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
}
.h-bar-label {
  width: 100px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}
.h-bar-track {
  flex: 1;
  height: 16px;
  background: rgba(255,255,255,0.04);
  border-radius: 3px;
  overflow: hidden;
}
.h-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.h-bar-val {
  width: 72px;
  text-align: right;
  color: var(--text);
  font-size: 11px;
  flex-shrink: 0;
}

/* Monthly bars */
.month-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
  padding-bottom: 20px;
  position: relative;
  overflow-x: auto;
}

.month-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 44px;
}

.month-col-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 100px;
}

.month-bar {
  width: 16px;
  border-radius: 3px 3px 0 0;
  transition: opacity 0.15s;
}
.month-bar:hover { opacity: 0.8; }

.month-label {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Donut chart */
.donut-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

.donut-legend { flex: 1; }
.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 12px;
}
.donut-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* Top table */
.top-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.top-table th {
  text-align: left;
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 600;
  color: var(--tan);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-bottom: 1px solid var(--border);
}
.top-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: var(--text);
}
.top-table tr:last-child td { border-bottom: none; }
.top-table td.num { text-align: right; color: var(--text-dim); }
.top-table td.emph { color: var(--tan); }

/* Costable breakdown */
.costable-row {
  display: flex;
  gap: 16px;
}
.costable-card {
  flex: 1;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  text-align: center;
}
.costable-card-val {
  font-size: 20px;
  font-weight: 700;
  color: var(--tan);
  font-family: var(--font-head);
}
.costable-card-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Legend */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
}
.legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* Empty states */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
}
.empty-state svg { opacity: 0.25; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── Tooltip ── */
.tooltip {
  position: fixed;
  background: rgba(13,17,23,0.95);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
  display: none;
}
.tooltip.visible { display: block; }
.tooltip-name { font-weight: 600; color: var(--tan); }
.tooltip-val { color: var(--text-dim); }

/* Scrollbar */
.tab-panel::-webkit-scrollbar { width: 4px; }
.tab-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* ── Mobile ── */
@media (max-width: 768px) {
  #mobile-bar { display: flex; }

  #app-layout { padding-top: var(--header-h); }

  #sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 60;
  }

  #sidebar.open { transform: translateX(0); }

  .sidebar-close-btn { display: flex; margin-left: auto; }

  #main-content { height: calc(100vh - var(--header-h)); }

  #stats-bar { flex-wrap: wrap; }
  .stat-card { flex: 0 0 50%; min-width: 0; }

  .job-card-metrics { flex-wrap: wrap; gap: 12px; }

  .h-bar-label { width: 70px; }
  .h-bar-val { width: 60px; }

  .chart-section { padding: 12px; }
}

/* ── Embed mode ── */
html.embed-mode #main-content { height: 100vh; }
