/* ==========================================================================
   Morningstar Moat Dashboard - Graphite Slate (石墨灰) Design System
   ========================================================================== */

:root {
  /* Slate & Graphite Core Palette */
  --bg-app: #0c0f14;
  --bg-surface: #141922;
  --bg-card: #19202c;
  --bg-card-hover: #1f2736;
  --bg-card-sub: #111620;
  
  --border-subtle: #232c3d;
  --border-card: #2c374c;
  --border-highlight: #3b4a66;

  /* Accent Colors */
  --accent-gold: #f59e0b;
  --accent-gold-glow: rgba(245, 158, 11, 0.15);
  --accent-emerald: #10b981;
  --accent-emerald-glow: rgba(16, 185, 129, 0.15);
  --accent-cyan: #38bdf8;
  --accent-blue: #60a5fa;
  --accent-rose: #f43f5e;
  --accent-purple: #a855f7;

  /* Typography Colors */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #0f172a;

  /* Fonts */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
}

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

body {
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.app-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 20px 60px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ==========================================================================
   Header & Navigation
   ========================================================================== */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  font-size: 28px;
  line-height: 1;
  padding: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
}

.nav-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.nav-title span {
  color: var(--accent-cyan);
  font-weight: 600;
}

.nav-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.domain-tag {
  color: var(--accent-gold);
  font-weight: 600;
}

.nav-meta {
  display: flex;
  align-items: center;
  gap: 14px;
}

.update-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: var(--accent-emerald);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-emerald);
  animation: pulse-dot-anim 2s infinite;
}

@keyframes pulse-dot-anim {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
  100% { opacity: 1; transform: scale(1); }
}

.btn-refresh {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-refresh:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--accent-cyan);
  transform: rotate(45deg);
}

/* ==========================================================================
   Stats Overview Grid
   ========================================================================== */
.stats-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-highlight);
}

.stat-card.highlight-zone1 {
  border-color: rgba(245, 158, 11, 0.4);
  background: linear-gradient(145deg, var(--bg-surface), rgba(245, 158, 11, 0.04));
}

.stat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-icon {
  font-size: 18px;
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-primary);
  letter-spacing: -0.03em;
}

.stat-subtext {
  font-size: 12px;
  color: var(--text-muted);
}

.text-gold { color: var(--accent-gold); }
.text-emerald { color: var(--accent-emerald); }
.text-cyan { color: var(--accent-cyan); }
.text-blue { color: var(--accent-blue); }
.text-rose { color: var(--accent-rose); }

/* ==========================================================================
   Section Cards (Common)
   ========================================================================== */
.section-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
}

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

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title .icon {
  font-size: 22px;
}

.section-title h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.section-intro {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.6;
}

.badge-pill {
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono);
}

.pill-gold {
  background: var(--accent-gold-glow);
  color: var(--accent-gold);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* ==========================================================================
   Zone 1 Spotlight Cards Grid
   ========================================================================== */
.zone1-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.zone1-item-card {
  background: var(--bg-card);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: var(--radius-md);
  padding: 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.zone1-item-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-gold), var(--accent-emerald));
}

.zone1-item-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-gold);
  box-shadow: 0 8px 24px rgba(245, 158, 11, 0.12);
}

.zone1-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.zone1-card-ticker {
  font-size: 18px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--accent-gold);
}

.zone1-card-name {
  font-size: 13px;
  color: var(--text-secondary);
}

.zone1-card-discount {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}

.zone1-card-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
  background: var(--bg-card-sub);
  padding: 10px;
  border-radius: var(--radius-sm);
}

.metric-item {
  display: flex;
  flex-direction: column;
}

.metric-item .m-lbl {
  font-size: 11px;
  color: var(--text-muted);
}

.metric-item .m-val {
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.zone1-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--accent-cyan);
  font-weight: 500;
  border-top: 1px solid var(--border-subtle);
  padding-top: 10px;
}

/* ==========================================================================
   Table Controls & Filters
   ========================================================================== */
.table-controls-header {
  flex-wrap: wrap;
  gap: 16px;
}

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

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 8px 32px 8px 36px;
  font-size: 13px;
  color: var(--text-primary);
  width: 240px;
  outline: none;
  transition: all 0.2s ease;
}

.search-box input:focus {
  border-color: var(--accent-cyan);
  width: 280px;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.15);
}

.clear-search {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  display: none;
}

.select-filter {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.select-filter:focus, .select-filter:hover {
  border-color: var(--border-highlight);
  color: var(--text-primary);
}

/* Quick Category Tabs */
.quick-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.tab-pill {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.tab-pill:hover {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-card);
}

.tab-pill.active {
  background: var(--bg-card-hover);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  font-weight: 600;
}

/* ==========================================================================
   Master Moat Table
   ========================================================================== */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  background: var(--bg-card-sub);
}

.moat-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.moat-table th {
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-card);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.moat-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

.moat-table tbody tr {
  transition: background-color 0.15s ease;
  cursor: pointer;
}

.moat-table tbody tr:hover {
  background-color: var(--bg-card-hover);
}

.moat-table tbody tr.row-zone1 {
  background: rgba(245, 158, 11, 0.03);
}

.table-loading {
  text-align: center;
  padding: 40px !important;
  color: var(--text-muted);
}

/* Column Specific Cells */
.cell-ticker-box {
  display: flex;
  flex-direction: column;
}

.cell-ticker {
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 14px;
  color: var(--accent-cyan);
}

.cell-company-name {
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-sector-tag {
  font-size: 11px;
  color: var(--text-muted);
}

.cell-price-box {
  font-family: var(--font-mono);
  display: flex;
  flex-direction: column;
}

.cell-curr-price {
  font-weight: 700;
  color: var(--text-primary);
}

.cell-fair-value {
  font-size: 11px;
  color: var(--text-muted);
}

.cell-pfv-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12px;
}

.pfv-deep {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.pfv-modest {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.pfv-fair {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.pfv-premium {
  background: rgba(244, 63, 94, 0.12);
  color: var(--accent-rose);
  border: 1px solid rgba(244, 63, 94, 0.25);
}

.cell-spread-box {
  font-family: var(--font-mono);
  display: flex;
  flex-direction: column;
}

.cell-spread-val {
  font-weight: 700;
  color: var(--accent-emerald);
}

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

.cell-pillar-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 200px;
}

.pillar-tag {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.cell-anti-fragile {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.anti-score-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.anti-score-high {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-gold);
}

.anti-score-mid {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
}

.anti-score-low {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
}

.cell-pios-badge {
  display: flex;
  flex-direction: column;
  font-family: var(--font-mono);
  font-size: 11px;
}

.pios-tier-1 { color: var(--accent-gold); font-weight: 700; }
.pios-tier-2 { color: var(--accent-cyan); font-weight: 700; }
.pios-tier-3 { color: var(--text-muted); }

.btn-table-action {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  color: var(--accent-cyan);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-table-action:hover {
  background: var(--accent-cyan);
  color: var(--text-inverse);
  border-color: var(--accent-cyan);
}

/* ==========================================================================
   Modal / Deep-Dive Drawer
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(8, 10, 14, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 999;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 880px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modal-pop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-pop {
  0% { transform: scale(0.95); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-card);
  background: var(--bg-card-sub);
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.modal-ticker-badge {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 800;
  color: var(--accent-gold);
  background: var(--bg-card);
  border: 1px solid rgba(245, 158, 11, 0.4);
  padding: 4px 10px;
  border-radius: var(--radius-md);
}

.modal-company-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-meta-info {
  font-size: 12px;
  color: var(--text-muted);
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-copy-link {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-copy-link:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.modal-close {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: var(--accent-rose);
  color: #fff;
  border-color: var(--accent-rose);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Modal Internal Layer Cards */
.layer-box {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.layer-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
}

.layer-box-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.layer-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-card-sub);
  color: var(--text-secondary);
}

.grid-metrics-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.sub-metric {
  background: var(--bg-card-sub);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
}

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

.sub-metric .s-val {
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

/* Pillars Progress Bars */
.pillars-bars-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pillar-row {
  display: grid;
  grid-template-columns: 120px 1fr 45px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.pillar-name {
  color: var(--text-secondary);
}

.pillar-bar-bg {
  background: var(--bg-card-sub);
  height: 8px;
  border-radius: var(--radius-full);
  overflow: hidden;
}

.pillar-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-blue));
  border-radius: var(--radius-full);
}

.pillar-score-text {
  font-family: var(--font-mono);
  font-weight: 700;
  text-align: right;
  color: var(--text-primary);
}

/* Anti-Fragility Quadrants */
.anti-quadrants-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quadrant-card {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.quadrant-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.quadrant-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.quadrant-score {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}

.quadrant-reason {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.llm-callout {
  background: rgba(56, 189, 248, 0.05);
  border-left: 3px solid var(--accent-cyan);
  padding: 10px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
  margin-top: 20px;
  padding-top: 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

.footer-links {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-links a:hover {
  color: var(--accent-cyan);
}

.footer-divider {
  color: var(--border-card);
}

.footer-note {
  max-width: 800px;
  line-height: 1.5;
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */
@media (max-width: 768px) {
  .app-container {
    padding: 12px 10px 40px 10px;
  }
  
  .navbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
  }

  .nav-meta {
    width: 100%;
    justify-content: space-between;
  }

  .filter-controls {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .search-box input {
    width: 100%;
  }

  .search-box input:focus {
    width: 100%;
  }

  .anti-quadrants-grid {
    grid-template-columns: 1fr;
  }
}
