/* ============================================================
   style.css — Premium Solid Terminal (Light), Responsive
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #0f172a;
  --text-sec: #475569;
  --text-muted: #94a3b8;
  --accent: #2563eb;
  --accent-dim: rgba(37,99,235,.08);
  --green: #10b981;
  --green-dim: rgba(16,185,129,.1);
  --green-text: #059669;
  --red: #ef4444;
  --red-dim: rgba(239,68,68,.1);
  --red-text: #dc2626;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}

/* ─── Header ─────────────────────────────────────── */
.header {
  background: #0f172a;
  color: #fff;
  padding: 0 5%;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  text-decoration: none;
  letter-spacing: -0.5px;
}
.header-brand span { color: #3b82f6; }

.header-right { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }

.online-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
  background: rgba(255,255,255,0.1);
  padding: 4px 12px;
  border-radius: 20px;
}

.pulse-dot {
  width: 8px; height: 8px;
  background: #34d399;
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(52,211,153,.5); }
  50%     { box-shadow: 0 0 0 6px rgba(52,211,153,0); }
}

.header-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: #94a3b8;
}

/* ─── Layout ─────────────────────── */
.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px 5%;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
  gap: 24px;
  margin-bottom: 24px;
}

.section { margin-bottom: 32px; animation: fadeIn .4s ease both; }
@keyframes fadeIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }

.section-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.section-bar .icon { font-size: 22px; }
.section-bar .title {
  font-size: 16px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text);
}
.section-bar .source {
  margin-left: auto;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 4px 12px;
  border-radius: 20px;
}

/* ─── Exchange Table ─────────────────────────────── */
.ex-table {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
  transition: box-shadow 0.3s;
}
.ex-table:hover { box-shadow: var(--shadow-hover); }

.ex-table table { width: 100%; border-collapse: collapse; min-width: 600px; }
.ex-table thead th {
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
  padding: 12px 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-sec);
  text-align: right;
  position: sticky; top: 0;
}
.ex-table thead th:first-child { text-align: left; }

.ex-table tbody tr.row-main {
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: all .2s ease;
}
.ex-table tbody tr.row-main:last-of-type { border-bottom: none; }
.ex-table tbody tr.row-main:hover { background: var(--surface-hover); }
.ex-table tbody tr.row-main.active { background: #eff6ff; }

.ex-table td {
  padding: 14px 20px;
  font-size: 14px;
  text-align: right;
  white-space: nowrap;
  vertical-align: middle;
}
.ex-table td:first-child { text-align: left; }

/* Symbol cell */
.sym-cell { display:flex; align-items:center; gap:12px; }
.sym-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  background: var(--surface-alt);
  flex-shrink: 0;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}
.sym-name { font-weight: 700; font-size: 14px; color: var(--text); }
.sym-code { font-size: 11px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; font-weight: 600; }
.sym-expand { margin-left: auto; font-size: 12px; color: var(--text-muted); transition: transform .3s cubic-bezier(0.4, 0, 0.2, 1); }
.row-main.active .sym-expand { transform: rotate(180deg); color: var(--accent); }

/* Price */
.td-price {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800; font-size: 15px; color: var(--text);
}

/* Change */
.chg {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700; font-size: 13px;
  padding: 4px 10px; border-radius: 6px;
  display: inline-block;
  min-width: 70px; text-align: center;
}
.chg.up   { color: var(--green-text); background: var(--green-dim); }
.chg.down { color: var(--red-text);   background: var(--red-dim); }
.chg.flat { color: var(--text-muted); background: var(--surface-alt); }

.td-unit { font-size: 12px; color: var(--text-muted); font-weight: 500; }

/* ─── Compare pills (multi-source) ───────────────── */
.cmp-wrap { display: flex; gap: 3px; justify-content: flex-end; flex-wrap: nowrap; margin-left: auto; }

.cmp-pill {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3px 5px; border-radius: 6px;
  background: var(--surface-alt); border: 1px solid var(--border);
  min-width: 0; flex: 1 1 auto;
  transition: all 0.2s; cursor: pointer;
}
.cmp-pill:hover { box-shadow: 0 1px 3px rgba(0,0,0,0.06); }

.cmp-pill .pill-src {
  font-size: 7px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .3px;
  color: var(--text-sec); margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}

/* Довідкові (НБУ/Мінфін) — один курс, muted стиль */
.cmp-pill.pill-ref {
  background: var(--surface); border-style: dashed; border-color: var(--border-light);
  opacity: 0.8;
}
.cmp-pill.pill-ref .pill-val {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700; font-size: 12px; color: var(--text-sec);
}

/* Банківські — продаж зверху, купівля знизу */
.cmp-pill.pill-bank .pill-bs {
  display: flex; flex-direction: column; align-items: center; gap: 1px; width: 100%;
}
.cmp-pill.pill-bank .pill-row {
  width: 100%; text-align: center;
}
.cmp-pill.pill-bank .pill-buy,
.cmp-pill.pill-bank .pill-sell {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 700; color: var(--text);
  padding: 1px 3px; border-radius: 3px; transition: all 0.2s;
  display: inline-block;
}
.cmp-pill.pill-bank .pill-sell { color: var(--red-text); }
.cmp-pill.pill-bank .pill-buy { color: var(--green-text); }

/* Найкращий курс — зелена рамка */
.v-best {
  background: var(--green-dim);
  outline: 2px solid var(--green);
  outline-offset: -1px;
  border-radius: 3px;
  font-weight: 800 !important;
}
/* Найгірший курс — червона рамка */
.v-worst {
  background: var(--red-dim);
  outline: 2px solid var(--red);
  outline-offset: -1px;
  border-radius: 3px;
  font-weight: 800 !important;
}

.cmp-pill.pill-off { opacity: 0.3; filter: grayscale(1); transform: scale(0.95); }

/* ─── Favorites ──────────────────────────────────── */
.fav-btn {
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: #cbd5e1; padding: 4px;
  transition: color 0.2s, transform 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.fav-btn:hover { color: #f59e0b; transform: scale(1.15); }
.is-fav .fav-btn { color: #f59e0b; text-shadow: 0 0 8px rgba(245, 158, 11, 0.4); }

body.show-fav .row-main:not(.is-fav) { display: none !important; }
body.show-fav .row-main:not(.is-fav) + .row-chart { display: none !important; }

.fav-toggle {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  font-size: 14px; font-weight: 700; color: #f8fafc;
  background: rgba(255,255,255,0.1); padding: 6px 14px; border-radius: 20px;
  transition: 0.3s;
}
.fav-toggle:hover { background: rgba(255,255,255,0.15); }
.fav-toggle input { display: none; }
.fav-slider {
  width: 36px; height: 20px; background: #64748b; border-radius: 20px;
  position: relative; transition: .3s;
}
.fav-slider::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; background: #fff; border-radius: 50%;
  transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
}
.fav-toggle input:checked + .fav-slider { background: #3b82f6; }
.fav-toggle input:checked + .fav-slider::after { transform: translateX(16px); }

/* ─── Expandable chart row ───────────────────────── */
.row-chart { display: none; }
.row-chart.open { display: table-row; animation: chartExpand 0.3s ease-out forwards; }
@keyframes chartExpand { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }
.row-chart td { padding: 0; background: #f8fafc; border-bottom: 1px solid var(--border); box-shadow: inset 0 4px 6px -4px rgba(0,0,0,0.05); }
.chart-container { padding: 24px 32px; height: 300px; }
.chart-container canvas { width: 100% !important; height: 100% !important; }

/* ─── Footer ─────────────────────────────────────── */
.footer {
  text-align: center; padding: 32px 20px;
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  border-top: 1px solid var(--border); margin-top: 24px;
}

/* ─── Responsive (mobile adaptation) ─────────────── */
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .header { padding: 12px 16px; height: auto; min-height: 60px; flex-direction: column; align-items: flex-start; gap: 10px; }
  .header-right { width: 100%; justify-content: space-between; }
  .header-time { display: none; }
  .container { padding: 16px 12px; }
  .ex-table table { min-width: 100%; }
  
  /* Make tables horizontally scrollable if needed, but try to fit */
  .ex-table td, .ex-table thead th { padding: 10px 12px; font-size: 13px; }
  .sym-icon { width: 30px; height: 30px; font-size: 16px; }
  .sym-name { font-size: 13px; }
  .sym-code { font-size: 10px; }
  .cmp-wrap { gap: 4px; justify-content: flex-start; }
  .cmp-pill { padding: 3px 6px; min-width: 55px; }
  .cmp-pill .pill-val { font-size: 12px; }
  .chart-container { height: 220px; padding: 16px; }
  
  /* Hide unit column on mobile to save space */
  .td-unit, .ex-table th:nth-child(3) { display: none; }
}

@media (max-width: 480px) {
  .section-bar .source { display: none; }
  .chg { min-width: 60px; font-size: 11px; padding: 4px 6px; }
  .sym-icon { display: none; }
  .fav-btn { font-size: 22px; padding: 0 4px 0 0; }
  .ex-table td, .ex-table thead th { padding: 10px 8px; }
  .cmp-pill .pill-src { font-size: 7px; }
}
