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

:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #293548;
  --text: #f1f5f9;
  --text-mute: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --green: #22c55e;
  --orange: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── App Container ───────────────────────────────────────────────────── */
.app { max-width: 800px; margin: 0 auto; padding: 16px; }

/* ─── Header ──────────────────────────────────────────────────────────── */
.header { text-align: center; padding: 24px 0 16px; }
.title { font-size: 1.5rem; font-weight: 700; }
.subtitle { font-size: 0.875rem; color: var(--text-mute); margin-top: 4px; }
.header-actions { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }

/* ─── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 16px; border: none; border-radius: var(--radius-sm);
  font-size: 0.875rem; cursor: pointer; transition: all 0.2s;
  font-weight: 500;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-outline {
  background: transparent; border: 1px solid var(--text-mute); color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-icon { padding: 4px 8px; font-size: 0.8rem; border-radius: 4px; }
.mt-1 { margin-top: 12px; }

/* ─── State Boxes ─────────────────────────────────────────────────────── */
.state-box {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 48px 24px; gap: 8px;
}
.hidden { display: none !important; }
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--bg-card);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-icon { font-size: 2rem; }
.error-detail { font-size: 0.875rem; color: var(--text-mute); }

/* ─── Content ─────────────────────────────────────────────────────────── */
.content { display: flex; flex-direction: column; gap: 20px; }

/* ─── Stats Bar ───────────────────────────────────────────────────────── */
.stats-bar {
  display: flex; justify-content: space-between;
  font-size: 0.75rem; color: var(--text-mute); padding: 8px 4px;
}

/* ─── Sections ────────────────────────────────────────────────────────── */
.section { background: var(--bg-card); border-radius: var(--radius); padding: 16px; }
.section-title { font-size: 1rem; font-weight: 600; margin-bottom: 12px; }

/* ─── Rate Cards ──────────────────────────────────────────────────────── */
.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.currency-card {
  background: var(--bg); border-radius: var(--radius-sm); padding: 14px;
  transition: transform 0.2s;
}
.currency-card:hover { transform: translateY(-1px); }

.card-row { display: flex; justify-content: space-between; align-items: center; }
.card-flags { display: flex; align-items: center; gap: 8px; }
.card-flag { font-size: 1.5rem; }
.card-label { font-size: 0.8rem; }
.card-code { font-size: 0.7rem; color: var(--text-mute); }
.card-rate { font-size: 1.1rem; font-weight: 700; text-align: right; }
.card-direction { font-size: 0.7rem; color: var(--text-mute); text-align: right; }
.card-history { font-size: 0.7rem; color: var(--text-mute); margin-top: 6px; }
.card-change {
  font-size: 0.75rem; margin-top: 4px; text-align: right;
}
.card-change.up { color: var(--green); }
.card-change.down { color: var(--danger); }

/* ─── Chart ───────────────────────────────────────────────────────────── */
.chart-controls { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.chart-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  padding: 4px 10px; border: 1px solid var(--text-mute); border-radius: 4px;
  background: transparent; color: var(--text-mute); font-size: 0.75rem;
  cursor: pointer; transition: all 0.2s;
}
.tab:hover { border-color: var(--primary); color: var(--primary); }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.chart-wrapper { position: relative; width: 100%; height: 220px; }
.chart-wrapper canvas { width: 100% !important; height: 100% !important; }
.chart-empty {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center; color: var(--text-mute);
  font-size: 0.875rem;
}

/* ─── Alert Form ──────────────────────────────────────────────────────── */
.alert-form {
  display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap;
}
.input {
  padding: 8px 12px; border: 1px solid var(--text-mute); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font-size: 0.875rem;
  outline: none; transition: border-color 0.2s;
}
.input:focus { border-color: var(--primary); }
select.input { cursor: pointer; }
input[type="number"].input { width: 100px; }

.alert-list { display: flex; flex-direction: column; gap: 6px; }
.alert-item {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg); padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 0.875rem;
}
.alert-item .badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 0.7rem; font-weight: 600;
}
.badge-on { background: var(--green); color: #fff; }
.badge-off { background: var(--text-mute); color: var(--bg); }
.alert-actions { display: flex; gap: 4px; }

/* ─── Toast ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card); color: var(--text); padding: 10px 20px;
  border-radius: var(--radius-sm); font-size: 0.875rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4); z-index: 100;
  transition: opacity 0.3s; border: 1px solid var(--primary);
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* ─── Footer ──────────────────────────────────────────────────────────── */
.footer {
  text-align: center; padding: 24px 0; font-size: 0.75rem; color: var(--text-mute);
  line-height: 2;
}

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .app { padding: 10px; }
  .card-grid { grid-template-columns: 1fr; }
  .title { font-size: 1.25rem; }
  .alert-form { flex-direction: column; }
  input[type="number"].input { width: 100%; }
  .chart-controls { flex-direction: column; }
  .chart-wrapper { height: 180px; }
}

/* ─── Modal ──────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-card); border-radius: var(--radius);
  max-width: 520px; width: 100%; max-height: 80vh; overflow-y: auto;
  padding: 24px;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 1.1rem; }

.settings-desc { font-size: 0.875rem; color: var(--text-mute); margin-bottom: 12px; }
.settings-error { color: var(--danger); font-size: 0.8rem; margin-top: 6px; }
.settings-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.settings-row label { font-size: 0.8rem; white-space: nowrap; min-width: 80px; color: var(--text-mute); }
.settings-row .input { flex: 1; }
.settings-group { margin-bottom: 12px; }
.settings-group h3 { font-size: 0.95rem; margin-bottom: 10px; }
.settings-divider { border: none; border-top: 1px solid #334155; margin: 16px 0; }

@media (max-width: 480px) {
  .modal { padding: 8px; align-items: flex-end; }
  .modal-content { max-height: 90vh; border-radius: var(--radius) var(--radius) 0 0; }
  .settings-row { flex-direction: column; align-items: flex-start; }
  .settings-row label { min-width: auto; }
}