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

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e1e4e8;
  --text: #1a1a2e;
  --text-secondary: #586069;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --green: #059669;
  --green-light: #d1fae5;
  --red: #dc2626;
  --red-light: #fee2e2;
  --amber: #d97706;
  --amber-light: #fef3c7;
  --slate: #6b7280;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

header {
  padding: 24px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
  color: var(--accent);
}

.logo h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: -1px;
}

/* Search */
.search-section {
  margin-bottom: 24px;
}

.search-box {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

#tickerInput {
  flex: 1;
  min-width: 200px;
  padding: 12px 16px;
  font-size: 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

#tickerInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

#analyzeBtn {
  padding: 12px 28px;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
}

#analyzeBtn:hover {
  background: #1d4ed8;
}

#analyzeBtn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 8px;
}

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

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

.examples {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.chip {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.chip:hover {
  background: #bfdbfe;
}

/* Error */
.error {
  margin-top: 12px;
  padding: 12px 16px;
  background: var(--red-light);
  color: var(--red);
  border-radius: var(--radius);
  font-size: 14px;
  border: 1px solid #fecaca;
}

/* Company Header */
.company-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
}

.company-header h2 {
  font-size: 22px;
  font-weight: 700;
}

.company-header .ticker-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-light);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
}

/* Tabs */
.nav-tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
}

.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* Score Card */
.score-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.score-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  flex-shrink: 0;
}

.score-excellent { background: var(--green-light); color: var(--green); }
.score-good { background: #dbeafe; color: var(--accent); }
.score-average { background: var(--amber-light); color: var(--amber); }
.score-poor { background: var(--red-light); color: var(--red); }

.score-info h3 {
  font-size: 16px;
  font-weight: 600;
}

.score-info p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Section */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
}

.section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section h3 .badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
}

/* Metric grid */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.metric-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.metric-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric-value {
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
}

.metric-value .trend {
  font-size: 13px;
  margin-left: 6px;
}

.metric-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Trend colors */
.trend-up { color: var(--green); }
.trend-down { color: var(--red); }
.trend-flat { color: var(--text-secondary); }
.trend-excellent { color: var(--green); }
.trend-healthy { color: var(--accent); }

/* Assessment tag */
.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 6px;
}

.tag-excellent { background: var(--green-light); color: var(--green); }
.tag-good { background: var(--accent-light); color: var(--accent); }
.tag-average { background: var(--amber-light); color: var(--amber); }
.tag-poor { background: var(--red-light); color: var(--red); }

/* Data table */
.data-table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table tr:hover td {
  background: #f9fafb;
}

.data-table .label-cell {
  font-weight: 500;
  color: var(--text);
  position: sticky;
  left: 0;
  background: white;
}

/* Valuation tags */
.val-tag { font-size: 12px; }

/* Hidden */
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 768px) {
  .app { padding: 0 12px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .search-box { flex-direction: column; }
  #tickerInput { min-width: auto; width: 100%; }
  #analyzeBtn { width: 100%; }
  .score-card { flex-direction: column; text-align: center; }
  .tab { font-size: 12px; padding: 8px 12px; }
}

/* ── Dimension Breakdown ── */
.dimension-breakdown {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.dim-header {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
}

.dim-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.dim-row:last-child {
  margin-bottom: 0;
}

.dim-label {
  width: 130px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  flex-shrink: 0;
  line-height: 1.3;
}

.dim-track {
  flex: 1;
  height: 10px;
  background: var(--bg);
  border-radius: 5px;
  overflow: hidden;
  min-width: 60px;
}

.dim-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.6s ease;
}

.dim-score {
  width: 32px;
  font-size: 14px;
  font-weight: 700;
  text-align: right;
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .dim-label {
    width: 100px;
    font-size: 12px;
  }
  .dim-row {
    gap: 8px;
  }
}

/* ── Anomaly / Red Flag Detection ── */
.anomaly-summary {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.anomaly-summary-item {
  flex: 1;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.anomaly-count {
  font-size: 28px;
  font-weight: 700;
  display: block;
}

.anomaly-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
  border-left: 4px solid var(--amber);
}

.anomaly-high {
  border-left-color: var(--red);
}

.anomaly-medium {
  border-left-color: var(--amber);
}

.anomaly-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.anomaly-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

.anomaly-badge.anomaly-high {
  background: var(--red-light);
  color: var(--red);
}

.anomaly-badge.anomaly-medium {
  background: var(--amber-light);
  color: var(--amber);
}

.anomaly-title {
  font-size: 15px;
  font-weight: 600;
}

.anomaly-detail {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  line-height: 1.6;
}

.anomaly-causes {
  background: var(--bg);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 10px;
}

.anomaly-causes-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.anomaly-causes ul {
  margin: 0;
  padding-left: 16px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.anomaly-causes li {
  margin-bottom: 2px;
}

.anomaly-metrics {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.anomaly-metric {
  padding: 6px 12px;
  background: var(--bg);
  border-radius: 6px;
  text-align: center;
  flex: 1;
  min-width: 80px;
}

.anomaly-metric-label {
  display: block;
  font-size: 10px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.anomaly-metric-value {
  display: block;
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
}

@media (max-width: 768px) {
  .anomaly-summary {
    flex-direction: column;
  }
  .anomaly-metrics {
    flex-direction: column;
  }
}


/* ── Quarterly Analysis ── */
.q-metric-section {
  margin-bottom: 16px;
}

.q-metric-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.q-table-wrap {
  overflow-x: auto;
}

.q-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.q-table th {
  text-align: left;
  padding: 6px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.q-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.q-table .q-growth-row td {
  font-size: 12px;
}

.q-growth-pos { color: var(--green); font-weight: 600; }
.q-growth-neg { color: var(--red); font-weight: 600; }

.q-avg-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.q-avg-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}
/* ── Profit Composition ── */

.waterfall-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.wf-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.wf-label {
  width: 110px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
  color: var(--text);
}

.wf-icon {
  font-size: 14px;
  width: 20px;
  text-align: center;
}

.wf-subtract {
  font-size: 10px;
  color: var(--text-secondary);
  background: var(--red-light);
  padding: 0 4px;
  border-radius: 3px;
  margin-left: 2px;
}

.wf-track {
  flex: 1;
  height: 22px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.wf-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
  min-width: 2px;
}

.wf-pct {
  width: 60px;
  text-align: right;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
  color: var(--green);
}

.wf-cost {
  color: var(--red);
}

.wf-pct-neg {
  color: var(--red);
}

.wf-val {
  width: 80px;
  text-align: right;
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .wf-label { width: 80px; font-size: 12px; }
  .wf-val { display: none; }
  .wf-pct { width: 50px; }
}

/* ── Revenue per employee ── */
.metric-card .metric-value {
  font-size: 16px;
}

/* ── Pie Chart Styles ── */

.pie-charts-row {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.pie-chart-wrap {
  flex: 0 1 auto;
  text-align: center;
  min-width: 180px;
}

.pie-chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.pie-legend {
  margin-top: 8px;
}

.pie-legend .data-table {
  font-size: 13px;
}

.pie-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.pie-legend td.label-cell {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tag-green {
  color: var(--green) !important;
  font-weight: 600;
}

.tag-red {
  color: var(--red) !important;
  font-weight: 600;
}

@media (max-width: 600px) {
  .pie-charts-row {
    flex-direction: column;
    align-items: center;
  }
  .pie-chart-wrap svg {
    max-width: 180px;
    height: auto;
  }
}
