:root {
  --bg: #f6f7f2;
  --paper: #ffffffcc;
  --ink: #1d2a21;
  --subtle: #5d6a61;
  --accent: #0f766e;
  --accent-2: #b45309;
  --line: #d8dfd4;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  overflow-x: hidden;
  background: radial-gradient(circle at 20% 20%, #e7f6ee, transparent 35%),
    radial-gradient(circle at 85% 10%, #fde8cf, transparent 30%),
    var(--bg);
}

.is-hidden {
  display: none !important;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  padding: 34px;
  text-align: center;
  background: #fffffff2;
  border: 1px solid #eef2eb;
  border-radius: 22px;
  box-shadow: 0 20px 60px #23452e1a;
}

.auth-card h1 {
  margin: 12px 0 8px;
}

.auth-card p {
  color: var(--subtle);
}

.auth-mark {
  width: 58px;
  height: 58px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border-radius: 16px;
  color: #fff;
  background: var(--accent);
  font-size: 1.8rem;
  font-weight: 800;
}

.google-login {
  width: 100%;
  min-height: 46px;
  margin-top: 12px;
}

.hero-account {
  float: right;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--subtle);
  font-size: 0.86rem;
}

.secondary-button {
  min-height: 32px;
  padding: 5px 10px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.print-report-header {
  display: none;
}

.bg-shape {
  position: fixed;
  border-radius: 999px;
  filter: blur(70px);
  z-index: -1;
  opacity: 0.35;
}

.bg-shape-1 {
  width: 360px;
  height: 360px;
  background: #34d399;
  left: -120px;
  top: 160px;
}

.bg-shape-2 {
  width: 420px;
  height: 420px;
  background: #f59e0b;
  right: -170px;
  top: 60px;
}

.container {
  width: min(1100px, 92vw);
  margin: 28px auto 40px;
  display: grid;
  gap: 14px;
}

.hero {
  background: var(--paper);
  border: 1px solid #eef2eb;
  border-radius: 18px;
  padding: 24px;
  animation: rise 0.45s ease;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 2.2vw, 2.2rem);
}

.hero p {
  margin: 0;
  color: var(--subtle);
}

.panel {
  background: var(--paper);
  border: 1px solid #eef2eb;
  border-radius: 16px;
  padding: 16px;
  animation: rise 0.55s ease;
}

.section-title {
  margin-top: 0;
}

.api-panel {
  display: grid;
  grid-template-columns: minmax(240px, 1.5fr) repeat(2, minmax(150px, 0.7fr)) auto;
  gap: 12px;
  align-items: end;
}

.quick-periods {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.saby-details > summary {
  justify-content: space-between;
}

.api-panel-copy {
  grid-column: 1 / -1;
}

.api-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.api-actions button {
  flex: 1 1 160px;
}

.quick-periods button {
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.quick-periods button:hover,
.quick-periods button.is-active {
  border-color: var(--accent);
  background: #e8f6f2;
  color: var(--accent);
}

.api-panel h2 {
  margin: 0;
}

.api-panel label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

.api-panel input {
  width: 100%;
}

.api-panel button {
  min-height: 42px;
}

.api-status {
  grid-column: 1 / -1;
  min-height: 22px;
  color: var(--subtle);
  font-size: 0.92rem;
}

.api-status.is-loading {
  color: var(--accent);
}

.api-status.is-success {
  color: #166534;
}

.api-status.is-error {
  color: #b91c1c;
}

.hint {
  margin: 8px 0 0;
  color: var(--subtle);
  font-size: 0.92rem;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  align-items: start;
}

.panel.filters {
  grid-template-columns: repeat(2, minmax(240px, 1fr));
}

.panel.filters > .section-title {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.filter-group {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.filter-group label {
  font-weight: 600;
}

.collapsible-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

.collapsible-summary::-webkit-details-marker {
  display: none;
}

.collapsible-summary::before {
  content: "▾";
  color: var(--subtle);
  font-size: 0.95rem;
}

.panel details:not([open]) > .collapsible-summary::before {
  content: "▸";
}

.collapsible-summary h2 {
  margin: 0;
}

.collapsible-content {
  margin-top: 8px;
}

.data-range-group {
  grid-column: 1 / -1;
}

.data-range-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
}

.data-range-item {
  display: grid;
  gap: 6px;
}

.data-range-label {
  color: var(--subtle);
  font-size: 0.86rem;
  font-weight: 600;
}

.filter-subtitle {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.exclusions-group {
  grid-column: 1 / -1;
}

.exclusions-details {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

.exclusions-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

.exclusions-summary::-webkit-details-marker {
  display: none;
}

.exclusions-summary::after {
  content: "▸";
  color: var(--subtle);
  font-size: 0.95rem;
  margin-left: auto;
}

.exclusions-details[open] .exclusions-summary::after {
  content: "▾";
}

.exclusion-summary-count {
  color: var(--subtle);
  font-size: 0.9rem;
  font-weight: 600;
}

.exclusions-content {
  margin-top: 10px;
}

select,
input[type="date"],
input[type="file"] {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
  width: 100%;
  min-width: 0;
}

select[multiple] {
  min-height: 150px;
  padding: 6px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
}

.stat {
  background: #fff;
  border: 1px solid #edf0ea;
  border-radius: 12px;
  padding: 12px;
}

.stat-title {
  margin: 0 0 4px;
  color: var(--subtle);
  font-size: 0.9rem;
}

.stat-value {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
}

h2 {
  margin: 4px 0 12px;
  font-size: 1.1rem;
}

.table-controls {
  margin-bottom: 10px;
  display: grid;
  gap: 8px;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.controls-row-grow .table-toggle {
  flex: 1 1 260px;
}

.controls-row-grow #exportExcel,
.controls-row-grow #exportPdf {
  margin-left: auto;
}

.table-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--subtle);
  font-size: 0.92rem;
}

.weather-impact-toggle {
  color: var(--ink);
  font-weight: 600;
}

.weather-impact-toggle-group .hint {
  margin-top: 2px;
}

.compare-custom {
  display: none;
}

.compare-custom.visible {
  display: grid;
}

.compare-preset {
  display: none;
}

.compare-preset.visible {
  display: grid;
}

.compare-period-switch {
  grid-column: 1 / -1;
}

.period-switch-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  gap: 8px;
  align-items: center;
}

.period-switch-side {
  display: grid;
  gap: 6px;
}

.period-switch-label {
  font-size: 0.85rem;
  color: var(--subtle);
  font-weight: 600;
}

.period-switch-arrow {
  color: #0f766e;
  font-size: 1.2rem;
  font-weight: 700;
  padding-top: 18px;
}

.compare-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.compare-header h2 {
  margin: 0 0 2px;
}

.compare-panel {
  border-color: #d8e4d6;
}

.compare-filters {
  background: #fbfdfb;
  border: 1px solid #e7efe4;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.compare-filters .filter-group label {
  font-size: 0.95rem;
}

.compare-stats .stat {
  border: 1px solid #dfe9dc;
  box-shadow: 0 1px 0 rgba(16, 24, 16, 0.02);
}

.compare-stats .stat--current {
  border-left: 4px solid #0f766e;
}

.compare-stats .stat--previous {
  border-left: 4px solid #6b7280;
}

.compare-stats .stat--diff-up {
  border-left: 4px solid #15803d;
  background: #f4fbf5;
}

.compare-stats .stat--diff-down {
  border-left: 4px solid #b91c1c;
  background: #fff6f6;
}

.stat-meta {
  margin: 4px 0 0;
  font-size: 0.86rem;
  color: var(--subtle);
}

.hidden-soft {
  display: none !important;
}

.exclusion-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 8px;
}

.exclusion-list {
  border: 1px solid #edf0ea;
  border-radius: 12px;
  background: #fff;
  padding: 8px;
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}

.exclusion-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid #eef2eb;
  border-radius: 10px;
  padding: 6px 8px;
}

.exclusion-item button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 4px 8px;
  font: inherit;
  cursor: pointer;
}

.exclusion-meta {
  color: var(--subtle);
  font-size: 0.82rem;
}

.table-controls select {
  min-width: 220px;
}

#exportPdf,
#downloadLog,
#exportExcel,
#buildForecast,
#expandAllRows,
#collapseAllRows,
#exportChartPng {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}

#expandAllRows:disabled,
#collapseAllRows:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#chart {
  display: block;
  width: 100%;
  height: 260px;
  max-width: 100%;
}

.chart-wrap {
  position: relative;
}

.chart-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.chart-controls h2 {
  margin: 0;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  min-width: 220px;
  max-width: 320px;
  padding: 8px 10px;
  border: 1px solid #d8dfd4;
  border-radius: 10px;
  background: #ffffffee;
  box-shadow: 0 8px 20px rgba(25, 40, 30, 0.14);
  color: #1d2a21;
  font-size: 12px;
  line-height: 1.35;
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 4px;
}

.chart-tooltip .muted {
  color: #5d6a61;
}

.seasonality-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 12px;
}

.forecast-filters {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  margin-bottom: 10px;
}

.seasonality-grid h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.table-wrap {
  max-height: 460px;
  overflow: auto;
  border: 1px solid #edf0ea;
  border-radius: 12px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid #edf0ea;
  font-size: 0.95rem;
}

.weather-cell {
  min-width: 250px;
  color: #2f3b33;
  font-size: 0.88rem;
  line-height: 1.35;
}

.weather-col {
  min-width: 250px;
}

.weather-line {
  display: inline-block;
}

.weather-muted {
  color: var(--subtle);
}

th {
  position: sticky;
  top: 0;
  background: #f8faf6;
  z-index: 1;
  white-space: nowrap;
}

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.empty {
  color: var(--subtle);
  padding: 12px;
}

.group-row td {
  background: #f8faf6;
  font-weight: 700;
}

.weekend-row td {
  background: #f6f9ff;
}

.holiday-row td {
  background: #fff5f5;
}

.day-badge {
  display: inline-block;
  margin-left: 6px;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.74rem;
  font-weight: 700;
  vertical-align: middle;
}

.day-badge-weekend {
  background: #dbeafe;
  color: #1d4ed8;
}

.day-badge-holiday {
  background: #fee2e2;
  color: #b91c1c;
}

.day-badge-mixed {
  background: #eef2ff;
  color: #374151;
}

body.weather-impact-off #weatherImpactSection,
body.weather-impact-off .weather-col {
  display: none !important;
}

.group-toggle {
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}

.warehouse-name {
  padding-left: 20px;
  color: var(--subtle);
}

@keyframes rise {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 800px) {
  .filters,
  .stats {
    grid-template-columns: 1fr;
  }

  .container {
    width: min(1100px, 95vw);
  }

  .hero {
    padding: 18px;
  }

  .panel {
    padding: 12px;
  }

  .controls-row-grow #exportExcel,
  .controls-row-grow #exportPdf {
    margin-left: 0;
  }

  h2 {
    font-size: 1rem;
    margin: 2px 0 10px;
  }

  .hint {
    font-size: 0.86rem;
  }

  select[multiple] {
    min-height: 120px;
  }

  #chart {
    height: 220px;
  }

  .chart-controls {
    align-items: flex-start;
  }

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

  .compare-header .table-toggle {
    width: 100%;
  }

  .compare-filters {
    padding: 10px;
  }

  .period-switch-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .data-range-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .period-switch-arrow {
    padding-top: 0;
    justify-self: center;
    transform: rotate(90deg);
  }

  .chart-controls .table-toggle {
    width: 100%;
  }

  .seasonality-grid {
    grid-template-columns: 1fr;
  }

  .forecast-filters {
    grid-template-columns: 1fr;
  }

  .weather-col,
  .weather-cell {
    min-width: 180px;
  }

  .exclusion-controls {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 8px 9px;
    font-size: 0.9rem;
  }
}

@media (max-width: 1200px) {
  .filters {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .panel.filters {
    grid-template-columns: 1fr;
  }

  .api-panel {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .api-panel-copy,
  .api-status {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .filters,
  .stats {
    grid-template-columns: 1fr;
  }

  .api-panel {
    grid-template-columns: 1fr;
  }

  .api-panel-copy,
  .api-status {
    grid-column: auto;
  }
}

#revenueSection {
  order: 1;
}

#weatherImpactSection,
#seasonalitySection,
#forecastSection,
#compareSection {
  order: 3;
}

#chartSection {
  order: 2;
}

@media print {
  .bg-shape,
  .hero,
  #sabySection,
  .api-panel,
  .filters,
  .table-controls,
  #downloadLog,
  .table-controls .hint,
  .chart-tooltip,
  .screen-only-heading {
    display: none !important;
  }

  @page {
    size: A4;
    margin: 10mm;
  }

  html,
  body {
    font-size: 10px;
  }

  body {
    background: #fff;
    color: #173126;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .container {
    width: 100%;
    margin: 0;
    gap: 5px;
  }

  .panel,
  .hero {
    border: none;
    background: #fff;
    padding: 0;
    animation: none;
    box-shadow: none;
  }

  .hero .hint {
    display: none;
  }

  .print-report-header {
    display: block;
    padding: 4mm 5mm;
    border-left: 4px solid #168c78;
    border-radius: 0 7px 7px 0;
    background: linear-gradient(90deg, #e8f7f2 0%, #f7fbf9 72%, #fff 100%);
    margin-bottom: 4mm;
  }

  .print-report-header h1 {
    margin: 0 0 2mm;
    font-size: 18px;
  }

  .print-report-header p {
    margin: 0;
    color: #58645c;
    font-size: 10px;
  }

  .print-hide-comparison #compareSection {
    display: none !important;
  }

  .print-hide-comparison #chartSection {
    display: none !important;
  }

  .print-hide-seasonality #seasonalitySection {
    display: none !important;
  }

  .print-hide-forecast #forecastSection {
    display: none !important;
  }

  body.weather-impact-off #weatherImpactSection {
    display: block !important;
  }

  body.weather-impact-off .weather-col {
    display: table-cell !important;
  }

  body.print-hide-weather-impact #weatherImpactSection {
    display: none !important;
  }

  #compareSection .filters {
    display: none !important;
  }

  #weatherImpactSection,
  #seasonalitySection,
  #forecastSection,
  #compareSection,
  #chartSection {
    margin-top: 4mm;
    padding-top: 2mm;
    border-top: 2px solid #dcefe8;
    break-inside: avoid;
  }

  details[open] > .collapsible-summary {
    list-style: none;
    pointer-events: none;
  }

  details[open] > .collapsible-summary::-webkit-details-marker {
    display: none;
  }

  .collapsible-content {
    padding: 0;
  }

  .table-wrap {
    max-height: none;
    overflow: visible;
    border: 1px solid #dfe5dd;
    border-radius: 8px;
    page-break-inside: auto;
  }

  h1 {
    font-size: 17px;
    margin-bottom: 2px;
  }

  h2 {
    font-size: 13px;
    margin: 6px 0 4px;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 6px;
    margin-bottom: 3mm;
  }

  .stat {
    border-color: #cfe6dc;
    border-radius: 6px;
    padding: 6px 8px;
    background: #f2faf7;
  }

  .stat:nth-child(3n + 1) {
    border-left: 3px solid #168c78;
  }

  .stat:nth-child(3n + 2) {
    border-left: 3px solid #e7a23b;
    background: #fff9ef;
  }

  .stat:nth-child(3n) {
    border-left: 3px solid #5478a8;
    background: #f3f7fc;
  }

  .stat-title {
    font-size: 9px;
  }

  .stat-value {
    font-size: 12px;
  }

  #weatherImpactStats {
    grid-template-columns: 1fr !important;
  }

  #weatherImpactStats .stat {
    max-width: none;
  }

  .print-single-day #detailTable th:first-child,
  .print-single-day #detailTable td:first-child {
    display: none !important;
  }

  th,
  td {
    font-size: 9px;
    padding: 3px 5px;
    line-height: 1.25;
    white-space: normal;
  }

  th {
    position: static !important;
    background: #247d6c;
    color: #fff;
    font-size: 9px;
  }

  thead {
    display: table-header-group;
  }

  tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .group-row td {
    background: #eaf6f1;
    color: #18372c;
  }

  tbody tr:nth-child(even):not(.group-row) td {
    background: #f7faf9;
  }

  .weekend-row td,
  .holiday-row td {
    background: #fff !important;
  }

  .day-badge {
    border: 1px solid #d5ddd4;
    background: transparent !important;
    color: #2e3a33 !important;
  }

  .group-toggle {
    color: #1f2d25;
    text-decoration: none;
    cursor: default;
    pointer-events: none;
  }

  #chartSection canvas {
    max-height: 95mm !important;
  }

  #chartSection .chart-controls button,
  #chartSection .chart-controls label {
    display: none !important;
  }
}
