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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  background: #f3f4f5;
  color: #2f3941;
  min-height: 100vh;
}

/* ── App shell ───────────────────────────────────────────────── */
#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

/* ── Header ──────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.header-left h1 {
  font-size: 22px;
  font-weight: 700;
  color: #1f2d3d;
  display: flex;
  align-items: center;
  gap: 8px;
}

.year-badge {
  font-size: 13px;
  font-weight: 600;
  background: #e8f0fe;
  color: #1a5dcc;
  padding: 2px 8px;
  border-radius: 10px;
}

.header-sub {
  font-size: 12px;
  color: #68737d;
  margin-top: 3px;
}

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

.subdomain-chip {
  font-size: 12px;
  font-weight: 500;
  color: #68737d;
  background: #fff;
  border: 1px solid #d8dcde;
  padding: 4px 10px;
  border-radius: 12px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #d8dcde;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #68737d;
  transition: background 0.15s;
}
.icon-btn:hover { background: #f3f4f5; }

/* ── Card container ──────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid #d8dcde;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}

/* ── Loading skeleton ────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -600px 0; }
  100% { background-position:  600px 0; }
}
.skeleton {
  border-radius: 6px;
  background: linear-gradient(90deg, #e8ebed 25%, #f3f4f5 50%, #e8ebed 75%);
  background-size: 1200px 100%;
  animation: shimmer 1.4s infinite linear;
  margin-bottom: 14px;
}
.skeleton-chart { height: 340px; }
.skeleton-card  { height: 68px;  }

/* ── Error banner ────────────────────────────────────────────── */
#error-banner {
  background: #fde8e8;
  border: 1px solid #f5a8a8;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  margin-bottom: 16px;
}
#error-message { font-size: 13px; color: #c72a1c; margin-bottom: 10px; }
#retry-btn {
  font-size: 13px; font-weight: 600; color: #fff;
  background: #c72a1c; border: none; border-radius: 6px;
  padding: 6px 18px; cursor: pointer;
}
#retry-btn:hover { background: #a3200f; }

/* ── Chart section ───────────────────────────────────────────── */
#chart-section {
  background: #fff;
  border: 1px solid #d8dcde;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}
.chart-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.section-title { font-size: 14px; font-weight: 600; color: #1f2d3d; }
.chart-wrapper { height: 340px; position: relative; }

/* ── Net indicator badge ─────────────────────────────────────── */
.net-indicator {
  display: inline-block;
  font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 12px;
  white-space: nowrap;
}
.net-indicator.positive { background: #d1f5e0; color: #187d3b; }
.net-indicator.negative { background: #fde8e8; color: #c72a1c; }
.net-indicator.neutral  { background: #f3f4f5; color: #68737d; }

/* ── Insights section ────────────────────────────────────────── */
#insights-section {
  background: #fff;
  border: 1px solid #d8dcde;
  border-radius: 8px;
  padding: 20px;
}
.section-subtitle { font-size: 12px; color: #68737d; margin-top: 2px; margin-bottom: 14px; }

/* ── Insights sub-header ─────────────────────────────────────── */
.insights-sub-header {
  font-size: 11px; font-weight: 600;
  color: #68737d; text-transform: uppercase; letter-spacing: 0.04em;
  margin: 16px 0 8px;
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.insights-sub-header:hover { color: #1a5dcc; }
#capacity-cards .insights-sub-header:first-child { margin-top: 0; }

/* ── Insight card ────────────────────────────────────────────── */
.insight-card {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  background: #f8f9f9;
  border: 1px solid #e9ebed;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 10px;
}
.insight-card:last-child { margin-bottom: 0; }

.insight-dimension {
  grid-column: 1; grid-row: 1;
  font-size: 11px; font-weight: 600;
  color: #68737d; text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.insight-description {
  grid-column: 1; grid-row: 2;
  font-size: 12px; color: #2f3941; word-break: break-word;
}
.delta-badge {
  grid-column: 2; grid-row: 1 / span 2;
  align-self: center;
  display: inline-block;
  font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 10px;
  white-space: nowrap; min-width: 56px; text-align: center;
}
.delta-badge.up      { background: #d1f5e0; color: #187d3b; }
.delta-badge.down    { background: #fde8e8; color: #c72a1c; }
.delta-badge.neutral { background: #f3f4f5; color: #68737d; }

/* ── Pattern card ────────────────────────────────────────────── */
.pattern-card {
  background: #f0f4ff;
  border: 1px solid #c5d3f5;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 10px;
}
.pattern-card:last-child { margin-bottom: 0; }

.pattern-header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
}
.pattern-icon {
  font-size: 13px;
  font-weight: 700;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.pattern-icon.positive { background: #d1f5e0; color: #187d3b; }
.pattern-icon.negative { background: #fde8e8; color: #c72a1c; }
.pattern-icon.neutral  { background: #e8ebed; color: #2f3941; }

.pattern-title {
  font-size: 12px;
  font-weight: 600;
  color: #1f2d3d;
}
.pattern-text {
  font-size: 12px;
  color: #2f3941;
  line-height: 1.55;
}

/* ── Mover narrative ─────────────────────────────────────────── */
.mover-narrative {
  font-size: 12px;
  color: #68737d;
  font-style: italic;
  margin-top: 10px;
  padding: 8px 12px;
  background: #f8f9f9;
  border-left: 3px solid #d8dcde;
  border-radius: 0 4px 4px 0;
  line-height: 1.55;
}

/* ── Settings overlay ────────────────────────────────────────── */
#settings-overlay {
  position: fixed; inset: 0;
  background: rgba(30, 40, 55, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
#settings-overlay.hidden { display: none; }

#settings-modal {
  background: #fff;
  border-radius: 10px;
  padding: 32px;
  width: 420px;
  max-width: 95vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
#settings-modal h2 { font-size: 18px; font-weight: 700; color: #1f2d3d; margin-bottom: 4px; }
.settings-subtitle  { font-size: 12px; color: #68737d; margin-bottom: 20px; }

#settings-modal label {
  display: block;
  font-size: 12px; font-weight: 600; color: #2f3941;
  margin-bottom: 5px; margin-top: 14px;
}
#settings-modal input {
  width: 100%; font-size: 13px;
  border: 1px solid #d8dcde; border-radius: 6px;
  padding: 8px 12px; outline: none;
  transition: border-color 0.15s;
}
#settings-modal input:focus { border-color: #1a5dcc; }

.input-row { display: flex; align-items: center; gap: 6px; }
.input-row input { flex: 1; }
.input-suffix { font-size: 12px; color: #68737d; white-space: nowrap; }

.token-hint { font-size: 11px; color: #68737d; margin-top: 6px; line-height: 1.5; }

#settings-error {
  margin-top: 12px;
  background: #fde8e8; border: 1px solid #f5a8a8;
  border-radius: 6px; padding: 8px 12px;
  font-size: 12px; color: #c72a1c;
}
#settings-error.hidden { display: none; }

#settings-save-btn {
  display: block; width: 100%;
  margin-top: 22px;
  font-size: 14px; font-weight: 600; color: #fff;
  background: #1a5dcc; border: none; border-radius: 6px;
  padding: 10px; cursor: pointer;
  transition: background 0.15s;
}
#settings-save-btn:hover { background: #1348a3; }

/* ── Validation table ────────────────────────────────────────── */
#validation-table {
  margin-top: 16px;
  overflow-x: auto;
}
#validation-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
#validation-table th {
  background: #f3f4f5;
  color: #68737d;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid #d8dcde;
  white-space: nowrap;
}
#validation-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #e9ebed;
  color: #2f3941;
  white-space: nowrap;
}
#validation-table tr:last-child td { border-bottom: none; }
#validation-table tr.current-week td { background: #f0f4ff; }
#validation-table .val-link {
  color: #1a5dcc;
  text-decoration: none;
  font-weight: 600;
}
#validation-table .val-link:hover { text-decoration: underline; }
.val-net-pos { color: #187d3b; font-weight: 600; }
.val-net-neg { color: #c72a1c; font-weight: 600; }

/* ── Backlog Health ──────────────────────────────────────────── */
#backlog-cards .insights-sub-header:first-child { margin-top: 0; }
.backlog-summary-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
@media (max-width: 600px) {
  .backlog-summary-row { grid-template-columns: repeat(2, 1fr); }
}
.backlog-stat {
  background: #f8f9f9;
  border: 1px solid #e9ebed;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.backlog-stat-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #68737d;
}
.backlog-stat-value {
  font-size: 20px;
  font-weight: 700;
  color: #2f3941;
  line-height: 1.2;
}
.backlog-stat-sub { font-size: 11px; color: #68737d; }
.backlog-table-wrap { overflow-x: auto; margin-top: 4px; }
.backlog-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.backlog-table th {
  background: #f3f4f5;
  color: #68737d;
  font-weight: 600;
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid #d8dcde;
  white-space: nowrap;
}
.backlog-table td {
  padding: 5px 10px;
  border-bottom: 1px solid #e9ebed;
  color: #2f3941;
  white-space: nowrap;
}
.backlog-table tr:last-child td { border-bottom: none; }
.backlog-table tr.current-week td { background: #f0f4ff; }
.backlog-table-note {
  font-size: 10px;
  color: #68737d;
  margin-top: 6px;
  margin-bottom: 0;
}

/* ── Week selector ───────────────────────────────────────────── */
.week-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.week-sel-label, .week-sel-vs {
  font-size: 12px;
  color: #68737d;
  font-weight: 500;
}
.week-selector select {
  font-size: 12px;
  font-weight: 600;
  color: #1f2d3d;
  background: #fff;
  border: 1px solid #d8dcde;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.week-selector select:focus { border-color: #1a5dcc; }

/* ── Prompt / AI Q&A section ─────────────────────────────────── */
#prompt-section {
  background: #fff;
  border: 1px solid #d8dcde;
  border-radius: 8px;
  padding: 20px;
  margin-top: 16px;
}

.prompt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.example-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 16px;
}

.example-q {
  font-size: 12px;
  font-weight: 500;
  color: #1a5dcc;
  background: #e8f0fe;
  border: 1px solid #c5d3f5;
  border-radius: 14px;
  padding: 4px 13px;
  cursor: pointer;
  transition: background 0.12s;
  line-height: 1.4;
}
.example-q:hover { background: #d0e1fd; }

/* ── Chat history ─────────────────────────────────────────────── */
#chat-history {
  max-height: 480px;
  overflow-y: auto;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#chat-history:empty { display: none; }

.chat-message {
  display: flex;
  flex-direction: column;
}
.chat-message.user  { align-items: flex-end; }
.chat-message.assistant { align-items: flex-start; }

.chat-role-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #68737d;
  margin-bottom: 3px;
  padding: 0 4px;
}

.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-message.user .chat-bubble {
  background: #1a5dcc;
  color: #fff;
  border-radius: 10px 10px 2px 10px;
}

.chat-message.assistant .chat-bubble {
  background: #f0f4ff;
  border: 1px solid #c5d3f5;
  color: #1f2d3d;
  border-radius: 10px 10px 10px 2px;
}

.chat-bubble.thinking {
  color: #68737d;
  font-style: italic;
}

/* ── Chat input row ───────────────────────────────────────────── */
.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#prompt-input {
  flex: 1;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid #d8dcde;
  border-radius: 6px;
  padding: 9px 12px;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.5;
}
#prompt-input:focus { border-color: #1a5dcc; }

#prompt-send-btn {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: #1a5dcc;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  height: 38px;
}
#prompt-send-btn:hover   { background: #1348a3; }
#prompt-send-btn:disabled { background: #8db4f5; cursor: not-allowed; }

/* ── Collapsible sub-headers ─────────────────────────────── */
.collapse-icon {
  font-size: 8px;
  color: #68737d;
  margin-left: 6px;
  flex-shrink: 0;
}

/* ── Engineering dependency mini chart ───────────────────── */
.dep-chart { display: block; }
.dep-bucket {
  display: grid;
  grid-template-columns: 60px 1fr 28px;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
}
.dep-label { font-size: 11px; color: #68737d; text-align: right; }
.dep-bar-wrap {
  height: 10px;
  background: #e8ebed;
  border-radius: 5px;
  overflow: hidden;
}
.dep-bar {
  height: 100%;
  background: #1a5dcc;
  border-radius: 5px;
  transition: width 0.3s;
}
.dep-count { font-size: 11px; color: #2f3941; font-weight: 600; }

/* ── Tab nav ─────────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid #d8dcde;
  margin: 12px 0 0;
  padding-bottom: 0;
}
.tab-btn {
  font-size: 13px;
  font-weight: 600;
  color: #68737d;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 8px 14px;
  cursor: pointer;
  transition: color 0.12s;
}
.tab-btn:hover  { color: #1f2d3d; }
.tab-btn.active { color: #1a5dcc; border-bottom-color: #1a5dcc; }

.tab-badge {
  font-size: 10px;
  font-weight: 700;
  background: #c72a1c;
  color: #fff;
  border-radius: 10px;
  padding: 1px 6px;
  margin-left: 4px;
  vertical-align: middle;
}

/* ── Spike section ───────────────────────────────────────────── */
.spike-section {
  background: #fff;
  border: 1px solid #d8dcde;
  border-radius: 8px;
  padding: 16px;
  margin-top: 12px;
}

.spike-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 4px;
}
.spike-banner-up      { background: #fde8e8; border: 1px solid #f5a8a8; }
.spike-banner-down    { background: #d1f5e0; border: 1px solid #8ed4b0; }
.spike-banner-neutral { background: #f3f4f5; border: 1px solid #d8dcde; }

.spike-banner-num {
  font-size: 32px;
  font-weight: 800;
  min-width: 56px;
  text-align: center;
}
.spike-banner-up   .spike-banner-num { color: #c72a1c; }
.spike-banner-down .spike-banner-num { color: #187d3b; }

.spike-banner-detail {
  font-size: 13px;
  color: #2f3941;
  line-height: 1.5;
}

/* ── Keyword / tag pills ─────────────────────────────────────── */
.spike-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  margin-bottom: 4px;
}
.spike-pill {
  font-size: 12px;
  background: #e8f0fe;
  color: #1a5dcc;
  border: 1px solid #c5d8fd;
  border-radius: 14px;
  padding: 3px 11px;
}
.spike-pill strong { color: #1f2d3d; }
.spike-pill-new {
  background: #fff3e0;
  color: #b45309;
  border-color: #f5c97a;
}
.spike-pill-regression {
  background: #fdf3ff;
  color: #7c3aed;
  border-color: #dbb6fb;
}

/* ── Spike top bar ───────────────────────────────────────────── */
.spike-top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.spike-top-bar .spike-banner { flex: 1; margin-bottom: 0; }

.spike-export-btn {
  font-size: 12px;
  font-weight: 600;
  background: #e8f0fe;
  color: #1a5dcc;
  border: 1px solid #c5d8fd;
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.spike-export-btn:hover { background: #d0e1fd; }

/* ── Component drill-down ────────────────────────────────────── */
.spike-component-card .insight-description { display: block; }
.spike-drilldown {
  margin-top: 8px;
  border-top: 1px solid #e9ebed;
  padding-top: 6px;
}
.spike-drillrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  font-size: 11px;
}
.spike-drillkey   { flex: 1; color: #2f3941; }
.spike-drillcounts { color: #68737d; white-space: nowrap; }

/* ── Spike ticket table ──────────────────────────────────────── */
.spike-table-wrap { overflow-x: auto; margin-top: 4px; }
.spike-ticket-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.spike-ticket-table thead th {
  background: #f3f4f5;
  color: #68737d;
  font-weight: 600;
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid #d8dcde;
  white-space: nowrap;
}
.spike-ticket-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #e9ebed;
  color: #2f3941;
  vertical-align: middle;
}
.spike-ticket-table tr:last-child td { border-bottom: none; }
.spike-ticket-table tr:hover td { background: #f8f9f9; }
.spike-subject {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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