/* === Reset & Variables === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #6366f1;
  --accent-rgb: 99, 102, 241;
  --accent-light: rgba(99, 102, 241, 0.12);
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface2: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text2: #64748b;
  --text3: #94a3b8;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
  --header-h: 52px;
  --tab-h: 46px;
  --base-h: 52px;
  --conv-h: 152px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* === App Shell === */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,0.06);
}

/* === Header === */
.header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, var(--accent), #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 17px;
  color: var(--text2);
  padding: 6px;
  border-radius: 8px;
  transition: background 0.12s;
  line-height: 1;
}
.icon-btn:hover { background: var(--surface2); }

/* === Tab Bar === */
.tab-bar {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tab-btn {
  flex: 1;
  padding: 7px;
  border-radius: 9px;
  border: none;
  background: var(--surface2);
  color: var(--text2);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.18s;
}
.tab-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.35);
}

/* === Base Picker Bar === */
.base-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: var(--base-h);
}
.base-label {
  font-size: 13px;
  color: var(--text2);
  white-space: nowrap;
}
.base-select {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.base-select:focus { border-color: var(--accent); }

/* === Rates Area === */
.rates-area {
  flex: 1;
  overflow-y: auto;
  padding-bottom: calc(var(--conv-h) + 24px);
}
.rates-area::-webkit-scrollbar { width: 4px; }
.rates-area::-webkit-scrollbar-track { background: transparent; }
.rates-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.state-msg {
  text-align: center;
  color: var(--text2);
  padding: 40px 16px;
  font-size: 14px;
}
.error-msg { color: var(--danger); }

/* === Rate Row === */
.rates-list { padding: 6px 0; }
.rate-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  transition: background 0.1s;
  user-select: none;
}
.rate-row:hover { background: var(--surface2); }
.rate-row:active { background: var(--accent-light); }

.rate-icon {
  width: 36px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.07);
  overflow: hidden;
}
.rate-icon.crypto-badge {
  font-size: 9px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.3px;
  border: none;
}
.rate-code {
  font-size: 15px;
  font-weight: 600;
  min-width: 48px;
  flex-shrink: 0;
}
.rate-val {
  margin-left: auto;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.rate-change {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 72px;
  justify-content: flex-end;
  flex-shrink: 0;
}
.rate-change--up   { color: #16a34a; }
.rate-change--down { color: #dc2626; }
.rate-change--neutral { color: #94a3b8; }
.rate-arrow { font-size: 10px; }

/* === Bottom panel (fixed: mini charts + converter stacked) === */
.bottom-panel {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  z-index: 20;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.07);
}

/* === Mini charts === */
.mini-charts {
  display: flex;
  gap: 8px;
  padding: 8px 12px 4px;
  border-bottom: 1px solid var(--border);
}
.mini-chart-card {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.mini-chart-header {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  padding: 5px 8px;
}
.mini-chart-eur { background: #1e3a5f; }
.mini-chart-usd { background: #a07820; }
.mini-chart-body {
  position: relative;
  height: 100px;
  background: #f8fafc;
}
.mini-chart-body canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* === Converter === */
.converter {
  padding: 10px 16px 18px;
}
.converter-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}
.conv-side {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.conv-input, .conv-result {
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 16px;
  font-weight: 600;
}
.conv-input {
  outline: none;
  color: var(--text);
  transition: border-color 0.15s;
}
.conv-input:focus { border-color: var(--accent); }
.conv-result {
  min-height: 41px;
  display: flex;
  align-items: center;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-select {
  width: 100%;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  outline: none;
}
.conv-eq {
  font-size: 20px;
  font-weight: 600;
  color: var(--text3);
  flex-shrink: 0;
}
.swap-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 7px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.swap-btn:hover { background: rgba(var(--accent-rgb), 0.2); }
.conv-rate {
  text-align: center;
  font-size: 12px;
  color: var(--text3);
  margin-top: 5px;
  min-height: 15px;
  font-variant-numeric: tabular-nums;
}

/* === Overlay === */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: opacity 0.22s;
}
.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.overlay.hidden .sheet,
.overlay.hidden .settings-panel {
  transform: translateY(100%);
}

/* === Detail Sheet === */
.sheet {
  width: 100%;
  max-width: 600px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 12px 16px 36px;
  max-height: 82vh;
  overflow-y: auto;
  transform: translateY(0);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 14px;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.sheet-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.fav-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 2px 6px;
  transition: transform 0.15s;
  line-height: 1;
}
.fav-btn:active { transform: scale(1.2); }

/* === Range Picker === */
.range-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  background: var(--surface2);
  padding: 4px;
  border-radius: 11px;
}
.range-btn {
  flex: 1;
  padding: 6px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.range-btn.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
}

/* === Chart === */
.chart-wrap {
  position: relative;
  height: 220px;
  margin-bottom: 6px;
}
.chart-wrap canvas {
  border-radius: var(--radius-sm);
}
.probe-box {
  text-align: center;
  font-size: 13px;
  color: var(--text2);
  margin-top: 8px;
  padding: 6px 12px;
  background: var(--surface2);
  border-radius: 8px;
  height: 32px;
}
.chart-footer {
  font-size: 11px;
  color: var(--text3);
  margin-top: 10px;
  line-height: 1.5;
}

/* === Settings Panel === */
.settings-panel {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 16px 20px 36px;
  transform: translateY(0);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 20px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.settings-label {
  font-size: 15px;
  font-weight: 500;
}
.settings-hint {
  font-size: 12px;
  color: var(--text3);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.stepper {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}
.step-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text);
}
.step-btn:hover { border-color: var(--accent); background: var(--accent-light); }
.step-btn:disabled { opacity: 0.35; cursor: default; }
.step-val {
  font-size: 18px;
  font-weight: 700;
  min-width: 24px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* === Legal links inside Settings === */
.settings-legal {
  display: flex;
  gap: 8px;
  align-items: center;
  padding-top: 16px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text3);
}
.settings-legal a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.settings-legal a:hover { text-decoration: underline; }

/* === Consent Banner === */
#consentBanner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #1e293b;
  color: #e2e8f0;
  padding: 14px 20px;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
}
html.show-consent #consentBanner {
  display: flex;
  animation: slideDown 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}
@media (min-width: 540px) {
  html.show-consent #consentBanner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
  }
}
.consent-text {
  font-size: 13px;
  line-height: 1.55;
  color: #cbd5e1;
  flex: 1;
}
.consent-text strong { color: #f1f5f9; }
.consent-text a {
  color: #a5b4fc;
  text-decoration: none;
  font-weight: 500;
}
.consent-text a:hover { text-decoration: underline; }
.consent-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.consent-btn {
  padding: 8px 18px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.consent-btn:hover { opacity: 0.85; }
.consent-decline {
  background: transparent;
  color: #94a3b8;
  border: 1px solid #475569;
}
.consent-accept {
  background: var(--accent);
  color: #fff;
}
