/* ======================================================
   Figure Shop P&L Simulator — Light Theme Design System
   ====================================================== */

:root {
  /* Color Palette — Clean White + Refined Accents */
  --bg-primary: #f8f9fc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f3f9;
  --bg-input: #f3f4f8;
  --bg-input-focus: #eef0f7;

  --border-subtle: rgba(99, 102, 241, 0.12);
  --border-active: rgba(99, 102, 241, 0.3);
  --border-light: #e5e7ef;

  --text-primary: #1a1d2e;
  --text-secondary: #4b5068;
  --text-muted: #8b90a5;
  --text-accent: #4f46e5;

  --accent-indigo: #4f46e5;
  --accent-violet: #7c3aed;
  --accent-emerald: #059669;
  --accent-rose: #e11d48;
  --accent-amber: #d97706;
  --accent-sky: #0284c7;
  --accent-teal: #0d9488;

  --gradient-primary: linear-gradient(135deg, #4f46e5, #7c3aed);
  --gradient-success: linear-gradient(135deg, #059669, #0d9488);
  --gradient-danger: linear-gradient(135deg, #e11d48, #f43f5e);
  --gradient-warm: linear-gradient(135deg, #d97706, #ea580c);
  --gradient-glass: linear-gradient(135deg, rgba(79, 70, 229, 0.04), rgba(124, 58, 237, 0.02));

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.08), 0 4px 8px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 20px rgba(79, 70, 229, 0.08);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 14px;
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  font-family: 'Inter', 'Noto Sans JP', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ======== App Container ======== */
.app-container {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 max(1.5rem, env(safe-area-inset-right)) 0 max(1.5rem, env(safe-area-inset-left));
}

/* ======== Header ======== */
.app-header {
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-width: 0;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.logo-icon {
  font-size: 2rem;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-primary);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.logo-section h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
  overflow-wrap: anywhere;
}

.header-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1rem;
  background: rgba(79, 70, 229, 0.06);
  border: 1px solid rgba(79, 70, 229, 0.15);
  border-radius: 100px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-indigo);
  flex-shrink: 0;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-emerald);
  animation: pulse-dot 2s ease infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

/* ======== KPI Strip ======== */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  padding: 1.5rem 0;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.kpi-breakeven::before { background: var(--gradient-primary); }
.kpi-daily::before { background: var(--gradient-warm); }
.kpi-cumulative::before { background: var(--gradient-success); }
.kpi-roi::before { background: linear-gradient(135deg, var(--accent-sky), var(--accent-teal)); }

.kpi-card:hover {
  border-color: var(--border-active);
  box-shadow: var(--shadow-md), var(--shadow-glow);
  transform: translateY(-2px);
}

.kpi-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.2;
  margin-bottom: 0.25rem;
  overflow-wrap: anywhere;
}

.kpi-breakeven .kpi-value { color: var(--accent-indigo); }
.kpi-daily .kpi-value { color: var(--accent-amber); }
.kpi-cumulative .kpi-value.positive { color: var(--accent-emerald); }
.kpi-cumulative .kpi-value.negative { color: var(--accent-rose); }
.kpi-roi .kpi-value { color: var(--accent-sky); }

.kpi-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ======== Content Grid ======== */
.content-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.5rem;
  padding-bottom: 3rem;
  min-width: 0;
}

/* ======== Input Panel ======== */
.input-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-self: start;
  overflow: visible;
  scrollbar-width: thin;
  scrollbar-color: rgba(79, 70, 229, 0.15) transparent;
  min-width: 0;
}

.input-panel::-webkit-scrollbar {
  width: 4px;
}

.input-panel::-webkit-scrollbar-thumb {
  background: rgba(79, 70, 229, 0.15);
  border-radius: 4px;
}

.panel-section {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-normal);
}

.panel-section:hover {
  border-color: var(--border-active);
  box-shadow: var(--shadow-md);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.section-icon {
  font-size: 1.1rem;
}

.input-group {
  margin-bottom: 0.85rem;
}

.input-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0 0.75rem;
  transition: all var(--transition-fast);
  min-height: 42px;
}

.input-wrapper:focus-within {
  border-color: var(--accent-indigo);
  background: var(--bg-input-focus);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.08);
}

.input-prefix,
.input-suffix {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-weight: 500;
  flex-shrink: 0;
}

.input-wrapper input {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 0;
  text-align: right;
}

.input-wrapper input::-webkit-inner-spin-button,
.input-wrapper input::-webkit-outer-spin-button {
  opacity: 0.3;
}

.input-hint {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-style: italic;
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0.5rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border-light);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.total-value {
  color: var(--accent-indigo);
  font-weight: 800;
  font-size: 0.95rem;
}

/* Seasonality Grid */
.seasonality-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.season-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.season-item label {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 600;
}

.season-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.25rem;
  text-align: center;
  outline: none;
  transition: all var(--transition-fast);
}

.season-input:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

.season-item span {
  font-size: 0.6rem;
  color: var(--text-muted);
}

/* ======== Charts Panel ======== */
.charts-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-normal);
  min-width: 0;
}

.chart-card:hover {
  box-shadow: var(--shadow-md);
}

.chart-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.chart-container {
  width: 100%;
  min-height: 280px;
  position: relative;
  overflow: hidden;
}

.chart-legend {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.75rem;
  font-weight: 500;
}

/* ======== Bar Chart (CSS-only) ======== */
.bar-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 240px;
  padding: 0 0.5rem;
  border-bottom: 1px solid var(--border-light);
  gap: 0.25rem;
}

.bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  position: relative;
}

.bar {
  width: 100%;
  max-width: 48px;
  border-radius: 6px 6px 0 0;
  transition: all var(--transition-smooth);
  position: relative;
  cursor: pointer;
  min-height: 2px;
}

.bar:hover {
  filter: brightness(1.08);
  transform: scaleX(1.05);
}

.bar.positive {
  background: var(--gradient-success);
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.15);
}

.bar.negative {
  background: var(--gradient-danger);
  box-shadow: 0 2px 8px rgba(225, 29, 72, 0.15);
}

.bar-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 600;
  padding-top: 0.35rem;
}

.bar-value {
  font-size: 0.6rem;
  font-weight: 700;
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.bar-group:hover .bar-value {
  opacity: 1;
}

.bar-value.positive { color: var(--accent-emerald); }
.bar-value.negative { color: var(--accent-rose); }

/* X-axis labels */
.chart-x-axis {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0.5rem 0;
}

.chart-x-label {
  flex: 1;
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ======== Cumulative Line Chart (CSS) ======== */
.line-chart-container {
  position: relative;
  height: 240px;
  padding: 0 0.5rem;
}

.line-chart-svg {
  width: 100%;
  height: 100%;
}

.line-chart-svg .grid-line {
  stroke: var(--border-light);
  stroke-dasharray: 4 4;
}

.line-chart-svg .zero-line {
  stroke: rgba(225, 29, 72, 0.3);
  stroke-width: 1.5;
  stroke-dasharray: 6 3;
}

.line-chart-svg .profit-line {
  fill: none;
  stroke: url(#lineGradient);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.line-chart-svg .profit-area {
  fill: url(#areaGradient);
  opacity: 0.2;
}

.line-chart-svg .data-point {
  fill: var(--bg-card);
  stroke-width: 2.5;
  cursor: pointer;
  transition: r var(--transition-fast);
}

.line-chart-svg .data-point:hover {
  r: 6;
}

.line-chart-svg .data-point.positive { stroke: var(--accent-emerald); }
.line-chart-svg .data-point.negative { stroke: var(--accent-rose); }

.line-chart-svg .y-label {
  fill: var(--text-muted);
  font-size: 10px;
  font-family: 'Inter', sans-serif;
}

.line-chart-svg .x-label {
  fill: var(--text-muted);
  font-size: 10px;
  font-family: 'Inter', sans-serif;
  text-anchor: middle;
}

.line-chart-svg .breakeven-marker {
  fill: var(--accent-amber);
  opacity: 0.9;
}

.line-chart-svg .breakeven-label {
  fill: var(--accent-amber);
  font-size: 11px;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
}

/* ======== Revenue Breakdown ======== */
.revenue-bars {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 200px;
  padding: 0 0.5rem;
  border-bottom: 1px solid var(--border-light);
  gap: 0.25rem;
}

.stacked-bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  max-width: 56px;
}

.stacked-bar {
  width: 100%;
  transition: all var(--transition-smooth);
  cursor: pointer;
  min-height: 1px;
}

.stacked-bar:hover {
  filter: brightness(1.08);
}

.stacked-bar.store {
  background: var(--gradient-primary);
  border-radius: 0;
}

.stacked-bar.store:first-child {
  border-radius: 6px 6px 0 0;
}

.stacked-bar.ec {
  background: linear-gradient(135deg, var(--accent-teal), var(--accent-sky));
  border-radius: 6px 6px 0 0;
}

.rev-legend {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 1rem;
}

.rev-legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.rev-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.rev-legend-dot.store { background: var(--accent-indigo); }
.rev-legend-dot.ec { background: var(--accent-teal); }

/* ======== Detail Table ======== */
.table-card {
  overflow: hidden;
}

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

#detailTable {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  font-size: 0.78rem;
}

#detailTable th {
  background: rgba(79, 70, 229, 0.04);
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.65rem;
  padding: 0.7rem 0.8rem;
  text-align: right;
  border-bottom: 2px solid var(--border-light);
  white-space: nowrap;
}

#detailTable th:first-child {
  text-align: center;
}

#detailTable td {
  padding: 0.6rem 0.8rem;
  text-align: right;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background var(--transition-fast);
}

#detailTable td:first-child {
  text-align: center;
  font-weight: 700;
  color: var(--accent-indigo);
}

#detailTable tbody tr:hover td {
  background: rgba(79, 70, 229, 0.03);
}

#detailTable td.positive { color: var(--accent-emerald); font-weight: 700; }
#detailTable td.negative { color: var(--accent-rose); font-weight: 700; }

#detailTable tfoot td {
  font-weight: 800;
  border-top: 2px solid var(--accent-indigo);
  padding: 0.8rem;
  background: rgba(79, 70, 229, 0.03);
  color: var(--text-primary);
}

/* ======== Sensitivity Analysis ======== */
.sensitivity-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.sensitivity-card {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1rem;
  transition: all var(--transition-normal);
}

.sensitivity-card:hover {
  border-color: var(--border-active);
  box-shadow: var(--shadow-md);
  background: var(--bg-card);
}

.sensitivity-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.sensitivity-bar-track {
  height: 8px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.sensitivity-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width var(--transition-smooth);
}

.sensitivity-bar-fill.positive { background: var(--gradient-success); }
.sensitivity-bar-fill.negative { background: var(--gradient-danger); }

.sensitivity-values {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
}

.sensitivity-values .label { color: var(--text-muted); }
.sensitivity-values .value { font-weight: 700; }
.sensitivity-values .value.positive { color: var(--accent-emerald); }
.sensitivity-values .value.negative { color: var(--accent-rose); }

/* ======== Footer ======== */
.app-footer {
  text-align: center;
  padding: 2rem 0;
  border-top: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 0.7rem;
}

/* ======== Responsive ======== */
@media (max-width: 1200px) {
  .content-grid {
    grid-template-columns: 320px 1fr;
  }
}

@media (max-width: 1024px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

  .input-panel {
    position: static;
    max-height: none;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .kpi-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  html { font-size: 14px; }

  .app-container {
    padding: 0 max(0.75rem, env(safe-area-inset-right)) 0 max(0.75rem, env(safe-area-inset-left));
  }

  /* --- Header --- */
  .app-header {
    padding: 0.75rem 0;
  }

  .header-content {
    align-items: flex-start;
  }

  .logo-section {
    align-items: flex-start;
    gap: 0.75rem;
  }

  .logo-icon {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 1.4rem;
    flex: 0 0 auto;
  }

  .logo-section h1 {
    font-size: clamp(0.95rem, 4.6vw, 1.05rem);
    line-height: 1.25;
  }

  .subtitle {
    font-size: 0.7rem;
    line-height: 1.35;
  }

  .header-badge { display: none; }

  /* --- KPI Strip --- */
  .kpi-strip {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    padding: 1rem 0;
  }

  .kpi-card {
    padding: 0.85rem 0.8rem;
  }

  .kpi-value {
    font-size: clamp(1.08rem, 6vw, 1.35rem);
  }

  .kpi-label {
    font-size: 0.6rem;
  }

  .kpi-sub {
    font-size: 0.6rem;
  }

  /* --- Input Panel: single column --- */
  .input-panel {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    padding-right: 0;
  }

  .panel-section {
    padding: 1rem;
  }

  .section-title {
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
  }

  /* iOS prevents zoom when font-size >= 16px on inputs */
  .input-wrapper input {
    font-size: 16px;
    min-height: 44px;
    padding: 0.45rem 0;
    text-align: left;
    color: var(--text-primary) !important;
    -moz-appearance: textfield;
    -webkit-appearance: none;
    appearance: none;
  }

  .input-wrapper input::-webkit-inner-spin-button,
  .input-wrapper input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    display: none;
    margin: 0;
  }

  .input-wrapper {
    padding: 0 0.6rem;
    overflow: visible;
    gap: 0.35rem;
    min-height: 46px;
  }

  .input-prefix {
    font-size: 0.75rem;
    color: var(--text-secondary);
  }

  .input-suffix {
    font-size: 0.65rem;
    color: var(--text-muted);
  }

  .input-group label {
    font-size: 0.7rem;
  }

  /* Seasonality: 4 columns still but tighter */
  .seasonality-grid {
    gap: 0.35rem;
  }

  .season-input {
    font-size: 16px;
    min-height: 42px;
    padding: 0.3rem 0.15rem;
  }

  .season-item label {
    font-size: 0.6rem;
  }

  .total-row {
    font-size: 0.75rem;
    padding: 0.5rem 0.25rem;
  }

  .total-value {
    font-size: 0.85rem;
  }

  /* --- Charts --- */
  .chart-card {
    padding: 1rem 0.85rem;
  }

  .chart-title {
    font-size: 0.8rem;
  }

  .chart-container {
    min-height: 200px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  .bar-chart {
    min-width: 330px;
    height: 180px;
    padding: 0 0.25rem;
  }

  .bar-label {
    font-size: 0.55rem;
  }

  .bar {
    max-width: 22px;
    border-radius: 4px 4px 0 0;
  }

  .revenue-bars {
    min-width: 330px;
    height: 150px;
    padding: 0 0.25rem;
  }

  .stacked-bar-group {
    max-width: 24px;
  }

  .chart-legend {
    font-size: 0.7rem;
  }

  .rev-legend {
    flex-wrap: wrap;
    gap: 1rem;
  }

  .rev-legend-item {
    font-size: 0.65rem;
  }

  /* --- Table: horizontal scroll with hint --- */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
  }

  #detailTable {
    min-width: 760px;
    font-size: 0.7rem;
  }

  #detailTable th {
    padding: 0.5rem 0.4rem;
    font-size: 0.55rem;
  }

  #detailTable td {
    padding: 0.4rem 0.4rem;
  }

  #detailTable th:first-child,
  #detailTable td:first-child,
  #detailTable tfoot td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--bg-card);
    box-shadow: 1px 0 0 var(--border-light);
  }

  #detailTable th:first-child {
    z-index: 3;
    background: #f7f7ff;
  }

  #detailTable tfoot td:first-child {
    background: #f7f7ff;
  }

  /* --- Sensitivity --- */
  .sensitivity-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .sensitivity-card {
    padding: 0.75rem;
  }

  .sensitivity-title {
    font-size: 0.7rem;
  }

  .sensitivity-values {
    gap: 0.75rem;
    align-items: flex-start;
    font-size: 0.65rem;
  }

  .sensitivity-values .value {
    text-align: right;
    white-space: nowrap;
  }

  /* --- Footer --- */
  .app-footer {
    padding: 1.25rem 0;
    font-size: 0.6rem;
  }
}

/* Extra small phones (SE, Mini) */
@media (max-width: 380px) {
  .app-container {
    padding: 0 max(0.6rem, env(safe-area-inset-right)) 0 max(0.6rem, env(safe-area-inset-left));
  }

  .kpi-strip {
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }

  .kpi-card {
    padding: 0.7rem 0.85rem;
  }

  .kpi-value {
    font-size: 1.2rem;
  }

  .seasonality-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .logo-section {
    gap: 0.5rem;
  }

  .chart-card {
    padding: 0.85rem 0.7rem;
  }

  .bar-chart,
  .revenue-bars {
    min-width: 310px;
  }
}

/* ======== Animations ======== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.kpi-card,
.panel-section,
.chart-card {
  animation: fadeInUp 0.5s ease both;
}

.kpi-card:nth-child(1) { animation-delay: 0.05s; }
.kpi-card:nth-child(2) { animation-delay: 0.1s; }
.kpi-card:nth-child(3) { animation-delay: 0.15s; }
.kpi-card:nth-child(4) { animation-delay: 0.2s; }

.chart-card:nth-child(1) { animation-delay: 0.1s; }
.chart-card:nth-child(2) { animation-delay: 0.15s; }
.chart-card:nth-child(3) { animation-delay: 0.2s; }
.chart-card:nth-child(4) { animation-delay: 0.25s; }
.chart-card:nth-child(5) { animation-delay: 0.3s; }

/* Tooltip */
.tooltip {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border-active);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.7rem;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 50;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}
