/* ============================================================
   KEIS Design System v1.1
   Kyrgyzstan Economic Intelligence System
   Фонд экономических исследований «Эл-Келечек»

   v1.1 changes: added JS-compatibility classes for index.html
   (.fx-ticker, .rate-card, .etl-widget, .skeleton, .tt-* tooltip
   in light theme, .card-meta as alias of .card-footer)
   ============================================================ */

/* ─── Fonts ─── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Source+Serif+4:wght@400;500;600;700&display=swap');

/* ─── Design tokens ─── */
:root {
  /* Surfaces */
  --bg: #F5F6F8;
  --surface: #FFFFFF;

  /* Brand (Эл-Келечек) */
  --primary: #644872;          /* deep purple */
  --primary-light: #8B6F99;
  --primary-bg: #F5F0F7;       /* soft purple background */
  --success: #37A999;          /* teal */
  --success-bg: #E6F5F2;
  --danger: #D9637A;           /* pink/coral */
  --danger-bg: #FBE9ED;
  --warning: #E89B4F;
  --warning-bg: #FDF3E5;
  --accent-soft: #FBD6C8;      /* peach — featured backgrounds */

  /* Text */
  --text: #1F2937;
  --text-muted: #6B7280;
  --text-faint: #9CA3AF;

  /* Borders */
  --border: #E5E7EB;
  --border-strong: #D1D5DB;

  /* Radii */
  --radius-card: 16px;
  --radius-hero: 20px;
  --radius-pill: 9999px;
  --radius-chip: 4px;

  /* Type families */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-serif: 'Source Serif 4', Georgia, serif;
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
img, svg { display: block; max-width: 100%; }

/* ─── Layout utilities ─── */
.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 32px;
}
.tabular { font-variant-numeric: tabular-nums; }
.serif { font-family: var(--font-serif); }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }

/* ─── Top bar ─── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-mark {
  font-weight: 700;
  font-size: 22px;
  color: var(--primary);
  letter-spacing: -0.02em;
}
.brand-sub {
  font-size: 13px;
  color: var(--text-muted);
}
.nav { display: flex; gap: 28px; }
.nav a {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 0;
  border-bottom: 2px solid transparent;
  transition: border-color .15s, color .15s;
}
.nav a.active {
  border-bottom-color: var(--primary);
  color: var(--primary);
}
.nav a:hover { color: var(--primary); }

/* ─── Status pill ─── */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--success-bg);
  color: var(--success);
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
}
.status-pill .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
}
.status-pill.warn { background: var(--warning-bg); color: var(--warning); }
.status-pill.warn .dot { background: var(--warning); }

/* ─── Generic ticker (new) ─── */
.ticker {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.ticker-inner {
  display: flex;
  gap: 48px;
  padding: 12px 32px;
  font-size: 13px;
  white-space: nowrap;
}
.ticker-item { display: inline-flex; align-items: baseline; gap: 8px; }
.ticker-label { color: var(--text-muted); }
.ticker-value { font-weight: 600; color: var(--text); }
.ticker-change.up { color: var(--success); font-weight: 500; }
.ticker-change.down { color: var(--danger); font-weight: 500; }
.ticker-change.flat { color: var(--text-muted); font-weight: 500; }

/* ─── Hero ─── */
.hero { padding: 56px 0 24px; }
.hero-kicker, .section-kicker, .insight-kicker {
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.hero-kicker { margin-bottom: 12px; }
.hero h1 {
  font-family: var(--font-serif);
  font-size: 42px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.02em;
  max-width: 720px;
  margin-bottom: 16px;
}
.hero-lede {
  font-size: 17px;
  color: var(--text-muted);
  max-width: 680px;
  line-height: 1.6;
  margin-bottom: 8px;
}
.hero-meta { font-size: 13px; color: var(--text-faint); }

/* ─── Hero cards (large) ─── */
.hero-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin: 40px 0 64px;
}
.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-hero);
  padding: 24px;
  transition: border-color .15s;
  cursor: pointer;
}
.hero-card:hover { border-color: var(--primary-light); }
.hero-card.featured {
  background: linear-gradient(180deg, #FBF5F7 0%, var(--surface) 100%);
  border-color: var(--accent-soft);
}
.hero-card-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 8px;
}
.hero-card-value {
  font-family: var(--font-serif);
  font-size: 38px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
}
.hero-card-unit {
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--text-muted);
  margin-left: 6px;
  font-weight: 400;
}
.hero-card-spark { margin-top: 16px; height: 36px; }
.hero-card-footer {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* ─── Deltas ─── */
.delta { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }
.delta.flat { color: var(--text-muted); }

/* ─── Section headers ─── */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin: 40px 0 24px;
  gap: 24px;
}
.section-head-left { max-width: 720px; }
.section-kicker { margin-bottom: 8px; }
.section-title {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
  margin-bottom: 10px;
}
.section-lede {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
}
.section-link {
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid var(--accent-soft);
  padding-bottom: 2px;
}

/* ─── Compact cards (regular) ─── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  transition: border-color .15s;
}
.card-clickable, .card[data-indicator-code] { cursor: pointer; }
.card-clickable:hover, .card[data-indicator-code]:hover { border-color: var(--primary-light); }
.card-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.4;
}
.card-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}
.card-unit {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: 4px;
  font-weight: 400;
  display: block;
  margin-top: 2px;
}
.card-spark, .card-sparkline { margin-top: 12px; height: 28px; }
.card-sparkline canvas { width: 100% !important; height: 28px !important; }
.card-footer, .card-meta {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-faint);
  align-items: center;
}

/* ─── Source badge ─── */
.badge-source {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  padding: 2px 8px;
  border-radius: var(--radius-chip);
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ─── Confidence badges (methodology) ─── */
.badge-conf {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-chip);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-conf.green  { background: rgba(55, 169, 153, 0.15); color: #2a8074; }
.badge-conf.yellow { background: rgba(251, 214, 200, 0.55); color: #a3603f; }
.badge-conf.red    { background: rgba(217, 99, 122, 0.15); color: #b14258; }


/* ─── Insight block ─── */
.insight {
  background: var(--primary-bg);
  border-radius: var(--radius-hero);
  padding: 32px;
  margin: 40px 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: center;
}
.insight-kicker { margin-bottom: 10px; }
.insight-title {
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.2;
  margin-bottom: 12px;
}
.insight-text {
  font-size: 15px;
  color: var(--text);
  line-height: 1.6;
}
.insight-chart {
  background: var(--surface);
  border-radius: 14px;
  padding: 16px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─── Confidence dots (data quality marker) ─── */
.conf-dot, .card-confidence {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}
.conf-green  { background: var(--success); }
.conf-yellow { background: var(--warning); }
.conf-red    { background: var(--danger); }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: #553A62; }
.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--primary-light); }

/* ─── Form controls (for /data filters and /simulation sliders) ─── */
.input, .select {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  transition: border-color .15s;
}
.input:focus, .select:focus {
  outline: none;
  border-color: var(--primary-light);
}
label.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

/* ─── Tables (for /data) ─── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius-card);
  overflow: hidden;
  border: 1px solid var(--border);
}
.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 14px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }

/* ─── Footer ─── */
.footer {
  margin-top: 80px;
  padding: 40px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}
.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 32px;
  margin-bottom: 32px;
}
.footer-col h4 {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}
.footer-col a {
  display: block;
  color: var(--text-muted);
  padding: 4px 0;
}
.footer-col a:hover { color: var(--primary); }
.footer-bottom {
  border-top: 1px solid var(--border);
  padding-top: 24px;
  display: flex;
  justify-content: space-between;
}

/* ─── Responsive (basic — full mobile is for later) ─── */
@media (max-width: 960px) {
  .hero h1 { font-size: 32px; }
  .section-title { font-size: 24px; }
  .hero-grid, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .insight { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .container { padding: 0 20px; }
  .hero { padding: 32px 0 16px; }
  .hero h1 { font-size: 28px; }
  .hero-grid, .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .nav { display: none; }
  .footer-grid { grid-template-columns: 1fr; }
  .footer-bottom { flex-direction: column; gap: 8px; }
}

/* ============================================================
   COMPATIBILITY LAYER (v1.1)
   For unchanged JS in index.html — old class names mapped to
   new visual style. Allows JS to keep working without rewrite.
   ============================================================ */

/* ─── FX ticker (legacy class names from JS) ─── */
.fx-ticker {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 32px;
  display: flex;
  gap: 32px;
  overflow-x: auto;
  font-size: 13px;
}
.fx-ticker::-webkit-scrollbar { height: 4px; }
.fx-ticker::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }
.fx-item {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.fx-pair { color: var(--text-muted); font-size: 12px; font-weight: 500; }
.fx-rate { color: var(--text); font-weight: 600; }
.fx-change {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: var(--radius-chip);
  font-weight: 500;
}
.fx-change.up { background: var(--success-bg); color: var(--success); }
.fx-change.down { background: var(--danger-bg); color: var(--danger); }

/* ─── Cards grid (legacy auto-fill) ─── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

/* ─── Rate card (для блока «Деньги») ─── */
.rates-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.rate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  cursor: pointer;
  transition: border-color .15s;
}
.rate-card:hover { border-color: var(--primary-light); }
.rate-card .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 10px;
}
.rate-card .value {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 600;
  color: var(--primary);
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.rate-card .sub {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 8px;
}
.sparkline-wrapper {
  height: 40px;
  margin-top: 12px;
}
.sparkline-wrapper canvas { width: 100% !important; height: 40px !important; }

/* ─── ETL status widget ─── */
.etl-widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px 24px;
  margin: 40px 0;
}
.etl-widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.etl-widget-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.etl-summary { display: flex; gap: 16px; font-size: 12px; }
.etl-summary span { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; }
.etl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.etl-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 12px;
}
.etl-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.etl-dot.green  { background: var(--success); }
.etl-dot.yellow { background: var(--warning); }
.etl-dot.red    { background: var(--danger); }
.etl-dot.grey   { background: var(--text-faint); }
.etl-source { color: var(--text); font-weight: 600; flex: 1; }
.etl-time   { color: var(--text-muted); white-space: nowrap; }
.etl-err {
  color: var(--danger);
  font-size: 10px;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

/* ─── Skeleton loading state ─── */
.skeleton {
  background: linear-gradient(90deg, var(--bg) 25%, #EBEDF0 50%, var(--bg) 75%);
  background-size: 200% 100%;
  animation: keis-shimmer 1.5s infinite;
  border-radius: 8px;
}
@keyframes keis-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ─── Error text ─── */
.error-text {
  font-size: 13px;
  color: var(--danger);
  padding: 8px 0;
}

/* ─── Tippy tooltip light theme ─── */
.tippy-box[data-theme~='keis'] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text);
  max-width: 320px;
  box-shadow: 0 8px 32px rgba(31, 41, 55, 0.12);
  padding: 4px;
}
.tippy-box[data-theme~='keis'] .tippy-arrow { color: var(--surface); }
.tt-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--primary);
  letter-spacing: -0.01em;
}
.tt-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 11px;
}
.tt-row span:last-child {
  color: var(--text);
  text-align: right;
  font-weight: 500;
}
.tt-desc {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  line-height: 1.5;
  font-size: 11px;
}
.tt-conf {
  display: inline-block;
  padding: 1px 6px;
  border-radius: var(--radius-chip);
  font-size: 10px;
  font-weight: 600;
  margin-left: 4px;
}
.tt-conf.green  { background: var(--success-bg); color: var(--success); }
.tt-conf.yellow { background: var(--warning-bg); color: var(--warning); }
.tt-conf.red    { background: var(--danger-bg);  color: var(--danger); }


/* ─── v1.1.2 patch: ticker centering + safe horizontal overflow ─── */
.fx-ticker { overflow-x: auto; }
.fx-item { flex-shrink: 0; }
.fx-item:first-child { margin-left: auto; }
.fx-item:last-child { margin-right: auto; }


/* ─── v1.1.3 patch: fix grid columns overflow ─── */
.hero-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-4    { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3    { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2    { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.hero-card, .card { min-width: 0; overflow: hidden; }
.hero-card-value, .card-value { word-break: break-word; }
