/* ── Reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --orange:   #FF9900;
  --dark:     #131921;
  --blue:     #146EB4;
  --light:    #EAEDED;
  --white:    #FFFFFF;
  --green:    #067D62;
  --red:      #D13212;
  --gray:     #5C6670;
  --border:   #D5D9D9;
  --hover:    #F0F2F2;
  --sidebar:  260px;
  --header:   56px;
  --radius:   8px;
  --shadow:   0 2px 8px rgba(0,0,0,0.12);
  --font:     'Amazon Ember', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* keep legacy variable names working */
  --amazon-orange:  var(--orange);
  --amazon-dark:    var(--dark);
  --amazon-blue:    var(--blue);
  --amazon-light:   var(--light);
  --amazon-white:   var(--white);
  --amazon-success: var(--green);
  --amazon-warn:    var(--red);
  --amazon-gray:    var(--gray);
  --amazon-border:  var(--border);
  --amazon-hover:   var(--hover);
}

body {
  font-family: var(--font);
  background: var(--light);
  color: var(--dark);
  min-height: 100vh;
}

/* ── Header ────────────────────────────────────────────────────────── */
.header {
  background: var(--dark);
  height: var(--header);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  border-bottom: 2px solid var(--orange);
}
.header-left             { display: flex; align-items: center; gap: 12px; }
.header-logo             { color: var(--white); font-size: 20px; font-weight: 700; letter-spacing: -.5px; }
.header-logo span        { color: var(--orange); }
.header-subtitle         { color: #ccc; font-size: 13px; margin-left: 8px; }
.header-status           { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 12px; color: #aaa; }
.status-dot              { width: 8px; height: 8px; border-radius: 50%; background: #555; }
.status-dot.connected    { background: var(--green); }
.status-dot.error        { background: var(--red); }

/* ── Layout ────────────────────────────────────────────────────────── */
.layout       { display: flex; padding-top: var(--header); min-height: 100vh; }

.sidebar {
  width: var(--sidebar);
  background: var(--white);
  border-right: 1px solid var(--border);
  position: fixed;
  top: var(--header); bottom: 0; left: 0;
  overflow-y: auto;
  padding: 20px 0;
  z-index: 50;
}
.sidebar-section { padding: 0 16px 20px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.sidebar-label   { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--gray); margin-bottom: 10px; }

.main-content  { margin-left: var(--sidebar); flex: 1; padding: 24px; max-width: calc(100vw - var(--sidebar)); }

/* ── Run metadata banner ───────────────────────────────────────────── */
.run-meta-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 12px;
  color: var(--gray);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.run-meta-card strong { color: var(--dark); }

/* Model summary card */
.model-summary-card {
  background: #f8faff;
  border: 1px solid #c8d8f0;
  border-left: 4px solid var(--blue);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 16px;
}
.model-summary-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 6px;
}
.model-summary-text {
  font-size: 12px;
  color: var(--gray);
  line-height: 1.6;
}
.model-summary-text strong { color: var(--dark); }
.model-summary-text em { font-style: italic; color: var(--blue); }

/* Filters card — compact, no shadow */
.filters-card {
  padding: 12px 18px !important;
  margin-bottom: 16px !important;
}

/* ── Cards ─────────────────────────────────────────────────────────── */
.card         { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; margin-bottom: 20px; box-shadow: var(--shadow); }
.card-title   { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.card-subtitle { font-size: 13px; color: var(--gray); margin-bottom: 16px; }
.card-header-row { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border: none; border-radius: 6px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all .15s; text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--orange); color: var(--dark); }
.btn-primary:hover:not(:disabled) { background: #e68a00; transform: translateY(-1px); }
.btn-secondary { background: var(--white); color: var(--dark); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--hover); }
.btn-sm  { padding: 6px 12px; font-size: 12px; }
.btn-lg  { padding: 14px 28px; font-size: 16px; border-radius: 8px; }

/* ── Home button (shared across all pages inside platform) ──────────────── */
.btn-page-home {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #ccc;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-page-home:hover {
  background: rgba(255,153,0,0.15);
  border-color: rgba(255,153,0,0.5);
  color: #ff9900;
}


/* ── Run Forecast button ───────────────────────────────────────────── */
.run-forecast-btn {
  width: 100%; justify-content: center;
  background: linear-gradient(135deg, var(--orange), #e68a00);
  color: var(--dark); font-size: 16px; padding: 16px;
  border-radius: var(--radius); border: none;
  box-shadow: 0 4px 12px rgba(255,153,0,.3);
}
.run-forecast-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(255,153,0,.4); }
.run-forecast-btn .btn-icon { font-size: 20px; }

/* ── Horizon selector ──────────────────────────────────────────────── */
.horizon-options         { display: flex; flex-direction: column; gap: 8px; }
.horizon-option          { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 2px solid var(--border); border-radius: 6px; cursor: pointer; transition: all .15s; }
.horizon-option:hover    { border-color: var(--orange); background: #fff8ee; }
.horizon-option.selected { border-color: var(--orange); background: #fff8ee; }
.horizon-option input[type="radio"] { accent-color: var(--orange); }
.horizon-option-label    { font-size: 14px; font-weight: 500; }
.horizon-option-desc     { font-size: 11px; color: var(--gray); }

/* ── Filters ───────────────────────────────────────────────────────── */
.filters-row  { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 20px; }
.filter-group { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.filter-label { font-size: 12px; font-weight: 600; color: var(--gray); text-transform: uppercase; letter-spacing: .5px; }
.filter-select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; background: var(--white); cursor: pointer; outline: none; transition: border-color .15s; }
.filter-select:focus { border-color: var(--blue); }

/* ── Period tabs ───────────────────────────────────────────────────── */
.period-tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid var(--border); }
.period-tab  { padding: 8px 16px; font-size: 13px; font-weight: 600; color: var(--gray); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.period-tab:hover  { color: var(--blue); }
.period-tab.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ── Chart ─────────────────────────────────────────────────────────── */
.chart-container { position: relative; height: 360px; margin-bottom: 8px; }
.chart-note      { font-size: 11px; color: var(--gray); margin-top: 6px; text-align: center; font-style: italic; }

/* ── Stats bar ─────────────────────────────────────────────────────── */
.stats-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card  { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--gray); margin-top: 4px; }
.stat-unit  { font-size: 10px; color: #aaa; margin-top: 2px; }
.stat-change         { font-size: 13px; font-weight: 600; margin-top: 4px; }
.stat-change.positive { color: var(--green); }
.stat-change.negative { color: var(--red); }

/* ── Table ─────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table          { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th       { background: var(--dark); color: var(--white); padding: 10px 14px; text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }
tbody tr       { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child { border-bottom: none; }
tbody td       { padding: 10px 14px; white-space: nowrap; }
.rate-cell     { font-weight: 700; color: var(--blue); }
.floor-cell      { color: var(--green); font-weight: 600; }
.ci-cell         { color: #999; font-size: 12px; }
.signal-cell     { max-width: 200px; white-space: normal; }
.prior-year-cell { color: var(--gray); font-size: 12px; }

/* ── Modal ─────────────────────────────────────────────────────────── */
.modal-overlay       { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; align-items: center; justify-content: center; }
.modal-overlay.open  { display: flex; }
.modal               { background: var(--white); border-radius: 12px; padding: 32px; max-width: 480px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-title         { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.modal-subtitle      { color: var(--gray); font-size: 14px; margin-bottom: 24px; line-height: 1.5; }
.modal-horizon-box   { background: #f8f8f8; border-radius: 8px; padding: 16px; margin-bottom: 8px; }
.modal-horizon-label { font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #333; }
.modal-horizon-value { font-size: 15px; color: var(--blue); font-weight: 500; }
.modal-note          { font-size: 12px; color: #888; margin-top: 8px; line-height: 1.4; }
.modal-actions       { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

/* ── Job status bar ────────────────────────────────────────────────── */
.job-status-bar         { display: none; align-items: center; gap: 12px; padding: 14px 18px; background: #EAF4FF; border: 1px solid var(--blue); border-radius: var(--radius); margin-bottom: 20px; }
.job-status-bar.visible { display: flex; }
.spinner    { width: 20px; height: 20px; border: 3px solid #cce4f7; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.job-status-text { font-size: 14px; font-weight: 500; }

/* ── Loading overlay ───────────────────────────────────────────────── */
.loading-overlay { text-align: center; padding: 60px 20px; }

/* ── History list ──────────────────────────────────────────────────── */
.history-list        { display: flex; flex-direction: column; gap: 8px; }
.history-empty       { padding: 12px; color: #888; font-size: 12px; }
.history-item        { display: flex; align-items: center; justify-content: space-between;
                       padding: 8px 10px; border: 1px solid var(--border);
                       border-radius: 6px; cursor: pointer; transition: all .15s; gap: 6px; }
.history-item:hover  { border-color: var(--blue); background: #f0f7ff; }
.history-item.active { border-color: var(--blue); background: #e8f2ff; }
.history-item-body   { flex: 1; min-width: 0; }
.history-item-id     { font-weight: 600; font-size: 12px; }
.history-item-meta   { font-size: 10px; color: var(--gray); margin-top: 1px; }
.history-item-date   { font-size: 10px; color: #aaa; white-space: nowrap; flex-shrink: 0; }

/* Delete button on history items */
.run-delete-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1;
  transition: color .15s, background .15s;
}
.run-delete-btn:hover { color: var(--red); background: #fff0ee; }

/* Cleanup row at bottom of history section */
.cleanup-row {
  display: none;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.cleanup-label  { font-size: 11px; color: var(--gray); white-space: nowrap; }
.cleanup-select {
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  background: var(--white);
  cursor: pointer;
  width: 48px;
}
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover:not(:disabled) { background: #b02a0e; }

/* ── Empty / error states ──────────────────────────────────────────── */
.empty-state       { text-align: center; padding: 60px 20px; color: var(--gray); }
.empty-state-icon  { font-size: 48px; margin-bottom: 16px; }
.empty-state-title { font-size: 18px; font-weight: 600; margin-bottom: 8px; color: var(--dark); }
.empty-state-text  { font-size: 14px; line-height: 1.6; }

/* ── Country / business badges ─────────────────────────────────────── */
.badge       { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.badge-us    { background: #e8f2ff; color: var(--blue); }
.badge-ca    { background: #fff0e0; color: #c45000; }
.badge-mx    { background: #e8f7ed; color: var(--green); }
.badge-na    { background: #1f2d40; color: #fff; font-weight: 700; }
.badge-amzl  { background: #f0f0f0; color: #333; }
.badge-amxl  { background: #fff8e0; color: #856000; }
.badge-rsr   { background: #f7e8ff; color: #7b00cc; }
.badge-all   { background: #146eb4; color: #fff; font-weight: 700; }

/* Combined rollup rows — subtle highlight to distinguish from individual rows */
tbody tr.combined-row { background: #f0f4ff; border-left: 3px solid var(--blue); }
tbody tr.combined-row:hover { background: #e4ecff; }
tbody tr.combined-row td { font-weight: 500; }

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar      { display: none; }
  .main-content { margin-left: 0; max-width: 100vw; }
  .chart-container { height: 280px; }
}
@media (max-width: 600px) {
  .stats-bar { grid-template-columns: 1fr 1fr; }
  .filters-row { flex-direction: column; }
  .filter-group { min-width: unset; width: 100%; }
}
