/* ── Reset & Base ──────────────────────────────────────────────────────────── */

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

:root {
  --navy:       #0A192F;
  --navy-soft:  #112240;
  --teal:       #4B8F8C;
  --teal-light: #6BA8A4;
  --bg:         #F2F0EB;
  --card:       #FFFFFF;
  --border:     #E5E1D8;
  --row-alt:    #F9F7F4;
  --row-hover:  #F0ECE4;
  --text:       #0A192F;
  --text-body:  #374151;
  --text-muted: #7A8599;
  --green:      #0D7571;
  --white:      #FFFFFF;
  --red:        #B91C1C;
  --font:       'JetBrains Mono', monospace;
  --radius:     8px;
  --radius-sm:  5px;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

#main-header {
  display: flex;
  align-items: center;
  background: var(--navy);
  padding: 0 36px;
  height: 50px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 40px;
}

.header-brand {
  flex-shrink: 0;
}

.logo {
  font-size: 13px;
  font-weight: 700;
  color: var(--teal-light);
  letter-spacing: 3px;
}

.logo-dot {
  color: var(--teal);
}

/* ── Tabs ──────────────────────────────────────────────────────────────────── */

.header-tabs {
  display: flex;
  gap: 0;
  height: 100%;
}

.tab {
  position: relative;
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  color: var(--teal-light);
  padding: 0 18px;
  cursor: pointer;
  letter-spacing: 0.3px;
  opacity: 0.5;
  transition: opacity 0.2s, color 0.2s;
  white-space: nowrap;
  height: 100%;
  display: flex;
  align-items: center;
}

.tab::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 12px;
  right: 12px;
  height: 2px;
  background: var(--teal);
  border-radius: 2px 2px 0 0;
  transform: scaleX(0);
  transition: transform 0.2s ease;
}

.tab:hover {
  opacity: 0.8;
}

.tab.active {
  color: var(--white);
  opacity: 1;
}

.tab.active::after {
  transform: scaleX(1);
}

/* ── Main ──────────────────────────────────────────────────────────────────── */

#app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 36px 40px;
}

/* ── Tab Panels ───────────────────────────────────────────────────────────── */

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

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

/* ── Panel Head ───────────────────────────────────────────────────────────── */

.panel-head {
  margin-bottom: 14px;
}

.panel-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--navy);
}

.panel-subtitle {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 3px;
  letter-spacing: 0.2px;
}

/* ── Filter Bar ───────────────────────────────────────────────────────────── */

.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label {
  font-size: 9.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.filter-custom {
  display: none;
}

.filter-custom.visible {
  display: flex;
}

select,
input[type="date"] {
  font-family: var(--font);
  font-size: 11.5px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--navy);
  outline: none;
  transition: border-color 0.2s;
  cursor: pointer;
}

select:hover,
input[type="date"]:hover {
  border-color: var(--teal-light);
}

select:focus,
input[type="date"]:focus {
  border-color: var(--teal);
}

.btn {
  font-family: var(--font);
  font-size: 10.5px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 8px 18px;
  letter-spacing: 0.4px;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-apply {
  background: var(--teal);
  color: var(--white);
}

.btn-apply:hover {
  background: var(--green);
}

.btn-secondary {
  background: transparent;
  color: var(--teal);
  border: 1px solid var(--teal);
}

.btn-secondary:hover {
  background: rgba(75, 143, 140, 0.1);
  color: var(--green);
  border-color: var(--green);
}

/* ── Table Wrapper ────────────────────────────────────────────────────────── */

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
}

/* ── Data Table ───────────────────────────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

/* Head */
.data-table thead {
  background: var(--navy);
}

.data-table th {
  font-size: 9.5px;
  font-weight: 600;
  color: var(--white);
  padding: 11px 14px;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  white-space: nowrap;
  user-select: none;
}

.data-table th.col-num {
  text-align: right;
}

/* Body */
.data-table td {
  font-size: 11.5px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--navy);
  white-space: nowrap;
}

.data-table td.col-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table td.col-name {
  font-weight: 500;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table tbody tr:nth-child(even) {
  background: var(--row-alt);
}

.data-table tbody tr {
  transition: background 0.15s;
}

.data-table tbody tr:hover {
  background: var(--row-hover);
}

/* Foot (totals) */
.data-table tfoot tr {
  background: var(--teal) !important;
}

.data-table tfoot td {
  color: var(--white);
  font-weight: 700;
  border-bottom: none;
  padding: 11px 14px;
  font-size: 11.5px;
}

/* ── States ────────────────────────────────────────────────────────────────── */

.state-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 56px 20px;
  color: var(--text-muted);
  font-size: 11.5px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.state-empty {
  padding: 56px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

.state-error {
  padding: 56px 20px;
  text-align: center;
  color: var(--red);
  font-size: 12px;
}

/* ── Placeholder (coming soon tabs) ───────────────────────────────────────── */

.state-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100px 20px;
}

.placeholder-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 6px;
}

.placeholder-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  #main-header {
    flex-direction: column;
    height: auto;
    padding: 12px 20px;
    gap: 10px;
  }

  .header-tabs {
    width: 100%;
    overflow-x: auto;
    height: auto;
  }

  .tab {
    padding: 8px 14px;
    font-size: 10px;
  }

  #app {
    padding: 20px 16px;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group {
    flex-wrap: wrap;
  }
}

/* ── Insights Section ─────────────────────────────────────────────────────── */

.insights-section {
  margin-top: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}

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

.insights-header h2 {
  font-size: 14px;
  color: var(--navy);
  font-weight: 600;
}

.insights-group {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.insights-group:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.insights-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.insights-group-header h3 {
  font-size: 12px;
  color: var(--navy);
  font-weight: 600;
}

.insights-filter {
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

/* ── Modal & Table ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10, 25, 47, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal-content {
  background: var(--white);
  padding: 24px;
  border-radius: var(--radius);
  width: 90%;
  max-width: 1000px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}
.modal-header h3 {
  margin: 0;
  color: var(--navy);
  font-size: 18px;
}
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--navy);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
.data-table th, .data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.data-table th {
  background: var(--bg);
  color: var(--navy);
  font-weight: 600;
  position: sticky;
  top: 0;
}
.data-table tbody tr:hover {
  background: var(--bg);
}

.chart-container {
  margin-bottom: 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.chart-container:last-child {
  margin-bottom: 0;
}

.charts-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 900px) {
  .charts-grid-2 {
    grid-template-columns: 1fr;
  }
}

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

.chart-header h3 {
  font-size: 14px;
  color: var(--navy);
  font-weight: 600;
}

.chart-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.metric-select,
.chart-type-select {
  font-size: 10.5px;
  padding: 4px 8px;
}

.plotly-chart {
  width: 100%;
  height: 260px;
}

.plotly-chart-wide {
  width: 100%;
  height: 300px;
}

.insights-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  color: var(--text-muted);
  font-size: 12px;
}
