:root {
  --bg: #eef2f8;
  --card: #ffffff;
  --card-2: #e9edf5;
  --border: rgba(22, 32, 58, 0.10);
  --text: #17203a;
  --muted: #5b667d;
  --blue: #3563d6;
  --cyan: #0891b2;
  --coral: #e5484d;
  --violet: #6d5bd0;
  --amber: #d97706;
  --green: #059669;
  --orange: #ea6a1c;
  --red: #e5484d;
  --gray: #64748b;
  --radius: 18px;
  --glow: radial-gradient(900px 480px at 50% -180px, #dbe4ff 0%, rgba(219, 228, 255, 0) 70%), var(--bg);
  --topbar-bg: rgba(238, 242, 248, 0.85);
  --modal-bg: linear-gradient(170deg, #ffffff, #eef2f8);
  --overlay: rgba(15, 23, 42, 0.45);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b1329;
  --card: #131f3f;
  --card-2: #182648;
  --border: rgba(255, 255, 255, 0.08);
  --text: #eef2fb;
  --muted: #8d99b8;
  --blue: #4f8cff;
  --cyan: #35e0f5;
  --coral: #ff5d5d;
  --violet: #a78bfa;
  --amber: #fbbf24;
  --green: #34d399;
  --orange: #fb923c;
  --red: #ff6b6b;
  --gray: #9aa7c7;
  --glow: radial-gradient(900px 480px at 50% -180px, #16255c 0%, rgba(22, 37, 92, 0) 70%), var(--bg);
  --topbar-bg: rgba(11, 19, 41, 0.82);
  --modal-bg: linear-gradient(170deg, #16234d, #0e1834);
  --overlay: rgba(3, 8, 22, 0.72);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { min-height: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--glow);
  color: var(--text);
  min-height: 100vh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  position: relative;
}

.hidden { display: none !important; }

/* ============ TOPBAR (STICKY) ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  position: relative;
}
.topbar-logo {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(79, 140, 255, 0.32);
}
.topbar-titles { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.topbar-brand { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.topbar-tagline { font-size: 11px; color: var(--muted); line-height: 1.2; }

/* ============ MENU HAMBURGUESA ============ */
.menu-btn {
  margin-left: auto;
  width: 40px;
  height: 40px;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}
.menu-bar {
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.menu-btn.open .menu-bar:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-btn.open .menu-bar:nth-child(2) { opacity: 0; }
.menu-btn.open .menu-bar:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 16px;
  width: 250px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.22);
}
.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  background: none;
  border: none;
  border-radius: 10px;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.menu-item:hover { background: var(--card-2); }
.menu-item:active { background: var(--card-2); }
.mi-icon { width: 20px; text-align: center; flex: none; }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }

/* ============ HEADER ============ */
.app-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }

.sun-icon {
  width: 42px; height: 42px; flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffd76a, #ff9f43);
  box-shadow: 0 6px 18px rgba(255, 165, 60, 0.35);
  display: grid; place-items: center;
}

.brand { font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }

/* ============ SECCION ============ */
.section { margin-top: 24px; }
.section-title { font-size: 16px; font-weight: 800; margin-bottom: 12px; }

/* ============ SYNC CARD ============ */
.sync-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.cal-icon {
  width: 38px; height: 38px; flex: none;
  border-radius: 10px;
  background: rgba(53, 224, 245, 0.13);
  color: var(--cyan);
  display: grid; place-items: center;
}
.sync-card .t { font-size: 11px; color: var(--muted); }
.sync-card .v { font-size: 13px; font-weight: 600; line-height: 1.35; }

/* ============ FUEL GRID / CARDS ============ */
.fuel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.fuel-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
.fuel-main {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
  width: 100%;
}
.fuel-icon { flex: none; line-height: 0; }
.fuel-icon svg { width: 38px; height: 38px; }
.fuel-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.fuel-badge {
  font-size: 10px;
  font-weight: 800;
  color: var(--fc);
  background: color-mix(in srgb, var(--fc) 16%, transparent);
  border-radius: 999px;
  padding: 4px 9px;
  letter-spacing: 0.02em;
}
.fuel-price {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.price-cur { font-size: 11px; font-weight: 600; color: var(--muted); }
.price-val { font-size: 23px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.diff { font-size: 11.5px; font-weight: 800; }
.diff.up { color: var(--green); }
.diff.down { color: var(--red); }
.diff.flat { color: var(--muted); }

/* ============ SUB HEADERS ============ */
.sub-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.back-btn {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: grid; place-items: center;
}
.sub-header h2 { font-size: 18px; font-weight: 800; }

/* ============ PAGINACION HISTORICO ============ */
.hist-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.hist-arrow {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, opacity 0.15s;
}
.hist-arrow:disabled { opacity: 0.35; cursor: default; }
.hist-arrow:active:not(:disabled) { background: var(--card-2); }
.hist-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  min-width: 0;
}
.hist-month {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-transform: capitalize;
}
.hist-year {
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
}

/* ============ ACCORDION HISTORICO ============ */
.accordion { display: flex; flex-direction: column; gap: 10px; }
.acc-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}
.acc-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.acc-head .acc-meta { display: flex; align-items: center; gap: 10px; }
.acc-head .count { font-size: 11px; color: var(--muted); font-weight: 600; }
.chev { color: var(--muted); transition: transform 0.25s ease; }
.acc-item.open .chev { transform: rotate(180deg); }
.acc-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s ease;
}
.acc-item.open .acc-body { grid-template-rows: 1fr; }
.acc-inner { overflow: hidden; min-height: 0; }
.acc-inner .fuel-grid { padding: 0 14px 14px; }
.acc-inner .fuel-card { background: var(--card-2); }

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--modal-bg);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 24px 20px 18px;
  text-align: center;
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}
.modal h3 { font-size: 18px; font-weight: 800; margin-bottom: 8px; }
.modal-lead { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 16px; }
.modal-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.modal-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px;
  text-decoration: none;
}
.btn-sync {
  width: 100%;
  font-size: 13.5px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #4f8cff, #3b6fe0);
  border: none;
  border-radius: 999px;
  padding: 13px;
  cursor: pointer;
}
.btn-sync:disabled { opacity: 0.55; cursor: wait; }
.sync-msg { min-height: 18px; font-size: 12px; margin-top: 10px; }
.sync-msg.ok { color: var(--green); }
.sync-msg.err { color: var(--red); }
.modal-foot { margin-top: 14px; font-size: 10.5px; color: var(--muted); line-height: 1.6; }
.modal-foot a { color: var(--blue); }

/* ============ ESTADOS ============ */
.loading { color: var(--muted); font-size: 13px; padding: 24px 0; text-align: center; grid-column: 1 / -1; }
.error-box {
  color: var(--red);
  background: rgba(255, 93, 93, 0.1);
  border: 1px solid rgba(255, 93, 93, 0.35);
  border-radius: 12px;
  padding: 14px;
  font-size: 13px;
  text-align: center;
  grid-column: 1 / -1;
}
