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

:root {
  --purple:      #57068C;
  --purple-dark: #3d0464;
  --purple-light:#f3eaf9;
  --text:        #1a1a1a;
  --text-muted:  #666;
  --border:      #ddd;
  --bg:          #f7f7f7;
  --white:       #fff;
  --red:         #c0392b;
  --radius:      6px;
  --shadow:      0 1px 4px rgba(0,0,0,.10);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Loading overlay ── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.88);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#loading-overlay[hidden] { display: none; }

.overlay-inner {
  text-align: center;
  color: var(--text-muted);
}
.overlay-inner p { margin-top: 14px; font-size: 14px; }

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Header ── */
header {
  background: var(--purple);
  color: var(--white);
  padding: 18px 24px;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.header-inner { max-width: 1200px; margin: 0 auto; }

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .01em;
}
.header-logo  { font-weight: 700; }
.header-divider { opacity: .5; }
.header-title { font-weight: 400; }

.header-subtitle {
  margin-top: 4px;
  font-size: 13px;
  opacity: .75;
}

/* ── Main layout ── */
main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Controls section ── */
.controls-section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.controls-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.shortcuts-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.shortcut-btn {
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.shortcut-btn:hover {
  border-color: var(--purple);
  color: var(--purple);
}
.shortcut-btn.active {
  background: var(--purple);
  border-color: var(--purple);
  color: var(--white);
}

/* ── Search ── */
.search-container {
  position: relative;
  max-width: 420px;
}
.search-container[hidden] { display: none; }

.search-input {
  width: 100%;
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--purple); }

.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  z-index: 100;
  max-height: 280px;
  overflow-y: auto;
}
.search-dropdown[hidden] { display: none; }

.search-result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .1s;
}
.search-result:hover { background: var(--purple-light); }

.result-ticker {
  font-weight: 700;
  font-size: 13px;
  color: var(--purple);
  min-width: 52px;
}
.result-name {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Error banner ── */
.error-banner {
  background: #fdf2f2;
  border: 1px solid #f5c6c6;
  color: var(--red);
  border-radius: var(--radius);
  padding: 9px 14px;
  font-size: 13px;
}
.error-banner[hidden] { display: none; }

/* ── Company chips ── */
.chips-section {
  min-height: 48px;
}

.chips-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.no-companies {
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 0;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--white);
  border: 1.5px solid var(--purple);
  border-radius: 24px;
  padding: 6px 14px 6px 12px;
  font-size: 13px;
  box-shadow: var(--shadow);
}
.chip--loading {
  border-color: var(--border);
  opacity: .75;
}

.chip-ticker {
  font-weight: 700;
  color: var(--purple);
}
.chip-name {
  color: var(--text-muted);
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 17px;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 0 0 2px;
  transition: color .1s;
}
.chip-remove:hover { color: var(--red); }

.chip-spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── Metrics table ── */
.table-section {
  flex: 1;
}

.metrics-table {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  background: var(--purple);
  color: var(--white);
  padding: 12px 16px;
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
}
thead th.metric-col {
  text-align: left;
  min-width: 200px;
}

.th-company {
  font-size: 13px;
  font-weight: 600;
}
.th-ticker {
  font-size: 11px;
  font-weight: 400;
  opacity: .8;
  margin-top: 2px;
}

/* Section header rows */
.section-row td {
  background: var(--purple-light);
  color: var(--purple-dark);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 7px 16px;
  border-top: 1px solid #d8c4ec;
}

tbody tr:not(.section-row) {
  border-bottom: 1px solid #f0f0f0;
  transition: background .1s;
}
tbody tr:not(.section-row):hover { background: #fafafa; }
tbody tr:not(.section-row):last-child { border-bottom: none; }

tbody td {
  padding: 10px 16px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
tbody td.metric-label {
  text-align: left;
  color: var(--text);
  font-size: 13.5px;
}

.na { color: #bbb; font-style: italic; }
.negative { color: var(--red); }

.cell-loading {
  display: inline-block;
  width: 60px; height: 12px;
  background: linear-gradient(90deg, #eee 25%, #e0e0e0 50%, #eee 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Specialized reporting note ── */
.flag-marker {
  color: #b8860b;
  font-style: normal;
  font-weight: 700;
}

.reporting-note {
  padding: 10px 16px;
  font-size: 12.5px;
  color: #7a6010;
  background: #fffbea;
  border-top: 1px solid #f0e08a;
}

/* ── Empty state ── */
.empty-state {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 16px 20px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--white);
}
footer a { color: var(--purple); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ── Responsive ── */
@media (max-width: 640px) {
  header { padding: 14px 16px; }
  main { padding: 16px 12px; gap: 14px; }
  .header-brand { font-size: 16px; }
  thead th, tbody td { padding: 9px 10px; }
  tbody td.metric-label { font-size: 12.5px; }
}
