/* ═══════════════════════════════════════════════════════════════════
   CHARTAGENT APP - Editorial / Newspaper Design
   Premium aesthetic inspired by NYT / Financial Times
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg: #FAFAF8;
  --bg-card: #FFFFFF;
  --text: #1A1A1A;
  --text-muted: #6B6B6B;
  --text-light: #999999;
  --border: #E5E5E3;
  --border-light: #F0F0EE;
  --accent: #C4A35A;
  --accent-hover: #B08D3E;
  --green: #2D8B4E;
  --green-bg: #E8F5E9;
  --red: #C62828;
  --red-bg: #FFEBEE;
  --amber: #E65100;
  --amber-bg: #FFF3E0;
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-sans: 'Inter', -apple-system, sans-serif;
  --sidebar-width: 240px;
  --sidebar-collapsed: 64px;
  --header-height: 56px;
  --radius: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ─── Reset / Base ─── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
}

img {
  display: block;
  max-width: 100%;
}

svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ─── Typography ─── */

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
}

h1 { font-size: 2rem; letter-spacing: -0.02em; }
h2 { font-size: 1.5rem; letter-spacing: -0.01em; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1rem; }

p {
  font-size: 0.933rem;
  line-height: 1.65;
  color: var(--text);
}

small {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ─── Layout ─── */

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-collapsed) 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "sidebar content";
  min-height: 100vh;
  width: 100%;
}

.app-layout.sidebar-expanded {
  grid-template-columns: var(--sidebar-width) 1fr;
}

.content-area {
  grid-area: content;
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.main-content {
  flex: 1;
  padding: 24px 32px 48px;
  max-width: 1280px;
  width: 100%;
}

/* ─── Sidebar ─── */

.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  height: 100vh;
  width: var(--sidebar-collapsed);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
}

.app-layout.sidebar-expanded .sidebar {
  width: var(--sidebar-width);
}

.sidebar-brand {
  padding: 0 20px 24px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 16px;
}

.sidebar-brand h1 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 450;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}

.sidebar-link:hover {
  color: var(--text);
  background: var(--border-light);
}

.sidebar-link.active {
  color: var(--text);
  background: var(--border-light);
  font-weight: 550;
}

.sidebar-link .icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Sidebar brand row for collapse toggle */
.sidebar-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-collapse-btn { padding: 4px; color: var(--text-muted); }
.sidebar-collapse-btn:hover { color: var(--text); }
/* When sidebar is NOT expanded (collapsed), center the brand row */
.app-layout:not(.sidebar-expanded) .sidebar-brand-row { justify-content: center; }

/* ─── Header ─── */

.app-header {
  position: sticky;
  top: 0;
  min-height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 32px;
  gap: 12px;
  z-index: 90;
  overflow: hidden;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mobile-menu-btn {
  display: none !important;
}

.header-title {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
}

.header-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.header-meta {
  font-size: 0.7rem;
  white-space: nowrap;
}

/* ─── Cards ─── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 600;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Tables ─── */

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  margin: 0 -24px;
  padding: 0 24px;
}

.card > .table-scroll:first-child {
  margin-top: -24px;
  padding-top: 24px;
}

.data-table {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table thead th {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 2px solid var(--text);
  text-align: left;
  white-space: nowrap;
}

.data-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.data-table tbody tr:nth-child(even) {
  background: rgba(0,0,0,0.015);
}

.data-table tbody tr:hover {
  background: rgba(0,0,0,0.025);
}

.data-table .text-right {
  text-align: right;
}

.data-table .text-center {
  text-align: center;
}

/* ─── Tags / Pills ─── */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 550;
  letter-spacing: 0.02em;
}

.tag-green {
  color: var(--green);
  background: var(--green-bg);
}

.tag-red {
  color: var(--red);
  background: var(--red-bg);
}

.tag-amber {
  color: var(--amber);
  background: var(--amber-bg);
}

.tag-yellow {
  color: #8B6E00;
  background: #FFF9C4;
}

.tag-neutral {
  color: var(--text-muted);
  background: var(--border-light);
}

/* ─── Buttons ─── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--text-light);
  box-shadow: var(--shadow-sm);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 12px;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--border-light);
}

.btn-sm {
  padding: 4px 12px;
  font-size: 0.8rem;
}

/* ─── Forms ─── */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input,
.select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  transition: border-color 0.15s ease;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(196,163,90,0.12);
}

.input::placeholder {
  color: var(--text-light);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B6B6B' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ─── Charts ─── */

.chart-container {
  position: relative;
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
}

.chart-container canvas {
  display: block;
  width: 100%;
}

/* ─── Metric Cards ─── */

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.metric-card .metric-label {
  font-size: 0.75rem;
  font-weight: 550;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.metric-card .metric-value {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
}

.metric-card .metric-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

/* ─── Heatmap Tiles ─── */

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 4px;
}

.heatmap-tile {
  padding: 14px 10px;
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.1s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.heatmap-tile:hover {
  transform: scale(1.03);
  box-shadow: var(--shadow);
  border-color: var(--border);
}

.heatmap-tile--active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(196,163,90,0.18);
}

.heatmap-tile .tile-value {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 4px;
}

.heatmap-tile .tile-ticker {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.3;
}

/* ─── Skeleton Loader ─── */

.skeleton {
  background: linear-gradient(90deg, var(--border-light) 25%, var(--border) 50%, var(--border-light) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 14px;
  margin-bottom: 10px;
  width: 80%;
}

.skeleton-title {
  height: 24px;
  margin-bottom: 16px;
  width: 50%;
}

.skeleton-card {
  height: 120px;
}

/* ─── Auth Forms ─── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}

.auth-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-form h1 {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  margin-bottom: 8px;
  text-align: center;
}

.auth-form .auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

.auth-form .form-group {
  margin-bottom: 20px;
}

.auth-form .btn {
  width: 100%;
  padding: 12px;
  font-size: 0.95rem;
}

.auth-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-footer a {
  font-weight: 550;
}

.auth-error {
  background: var(--red-bg);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.auth-waiting {
  text-align: center;
  padding: 48px 24px;
}

.auth-waiting h2 {
  margin-bottom: 12px;
}

.auth-waiting p {
  color: var(--text-muted);
}

/* ─── Responsive ─── */

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .sidebar.mobile-open {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    box-shadow: 4px 0 24px rgba(0,0,0,0.12);
  }

  .mobile-menu-btn {
    display: flex !important;
  }

  .sidebar-toggle-btn {
    display: none !important;
  }

  .app-header {
    padding: 0 16px;
  }

  .main-content {
    padding: 16px 16px 32px;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .heatmap-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  }
}

@media (max-width: 480px) {
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .auth-form {
    padding: 24px;
  }
}

/* ─── Utility Classes ─── */

.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-yellow { color: #B8960C; }
.text-muted { color: var(--text-muted); }
.text-light { color: var(--text-light); }
.text-center { text-align: center; }
.text-right { text-align: right; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }

.gap-xs { gap: 4px; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.gap-lg { gap: 24px; }
.gap-xl { gap: 32px; }

.mt-xs { margin-top: 4px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mt-xl { margin-top: 32px; }

.mb-xs { margin-bottom: 4px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 16px; }
.mb-lg { margin-bottom: 24px; }
.mb-xl { margin-bottom: 32px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-title {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 24px;
  letter-spacing: -0.02em;
}

.section-title {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

/* Spin animation for loader */
.spin { animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Compact metric card variant */
.metric-card--compact { padding: 12px 20px; }
.metric-card--compact .metric-value { font-size: 1.25rem; }

/* Hero card value classes (DashboardView) */
.hero-value { font-family: var(--font-serif); font-size: 2rem; font-weight: 700; line-height: 1.1; }
.hero-value--sm { font-family: var(--font-serif); font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.hero-stat { font-size: 1.25rem; font-weight: 600; }

/* ─── Ticker Cell with Insight Link ─── */

.ticker-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}

.insight-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.15s ease;
  flex-shrink: 0;
}

.insight-link:hover { opacity: 1; }
.insight-link.insight-negative { color: var(--red); }
.insight-link.insight-positive { color: var(--green); }

/* ─── Insight View ─── */

.insight-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--text);
}

.insight-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.insight-ticker {
  font-family: var(--font-serif);
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}

.insight-name {
  font-size: 1.1rem;
  color: var(--text-muted);
}

.insight-back-btn {
  gap: 4px;
}

.insight-analysis {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  margin-bottom: 24px;
}

.insight-analysis-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}

.insight-analysis-content {
  font-size: 0.95rem;
  line-height: 1.85;
  color: var(--text);
  max-width: 800px;
}

.insight-analysis-content strong {
  font-weight: 650;
  color: var(--text);
}

.insight-analysis-content p {
  margin-bottom: 16px;
}

.insight-analysis-content p:last-child {
  margin-bottom: 0;
}

.insight-citations {
  background: var(--border-light);
  padding: 20px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.insight-citations-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.insight-citations-list {
  list-style: none;
}

.insight-citations-list li {
  margin-bottom: 6px;
}

.insight-citation-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.insight-citation-link:hover {
  color: var(--text);
  text-decoration: underline;
}

.insight-fallback {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--amber);
  background: var(--amber-bg);
  padding: 8px 14px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.insight-meta {
  font-size: 0.75rem;
  color: var(--text-light);
}

.insight-not-found {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}

.insight-not-found h3 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  margin-top: 16px;
  margin-bottom: 8px;
  color: var(--text);
}

@media (max-width: 768px) {
  .insight-ticker { font-size: 1.75rem; }
  .insight-analysis { padding: 20px 0; }
}

/* ─── Header Avatar Button ─── */

.header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  transition: border-color 0.15s ease;
  padding: 0;
}

.header-avatar:hover {
  border-color: var(--accent);
}

.header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ─── Profile Page ─── */

.profile-header {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 32px;
}

.profile-avatar-wrapper {
  position: relative;
  cursor: pointer;
}

.profile-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 3px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-serif);
  font-size: 2.5rem;
  font-weight: 700;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-avatar-overlay {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.profile-avatar-overlay:hover {
  color: var(--text);
}

.profile-info h2 {
  margin: 0;
  font-family: var(--font-serif);
}

.profile-info .text-muted {
  font-size: 0.85rem;
}
