:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface2: #18213a;
  --border: #222c45;
  --text: #e9edf6;
  --muted: #8a95ad;
  --accent: #7c5cff;
  --cyan: #22d3ee;
  --good: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

.boot { padding: 40vh 0 0; text-align: center; color: var(--muted); }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding: calc(var(--safe-top) + 6px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 40px) calc(var(--safe-left) + 16px);
}

/* En-tête */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0 8px;
}
.topbar h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; cursor: pointer; font-size: 18px;
}
.back { color: var(--cyan); font-size: 15px; display: inline-flex; align-items: center; gap: 4px; }

/* Période */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; margin: 8px 0 14px; }
.seg button { border: 0; background: transparent; padding: 8px 0; border-radius: 10px; color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--surface2); color: var(--text); box-shadow: 0 0 0 1px var(--border) inset; }

/* Grand compteur */
.hero {
  background: radial-gradient(120% 140% at 0% 0%, rgba(124,92,255,.28), transparent 60%), radial-gradient(100% 120% at 100% 100%, rgba(34,211,238,.18), transparent 55%), var(--surface);
  border: 1px solid var(--border); border-radius: 24px; padding: 20px 20px 18px; margin-bottom: 14px;
}
.hero .label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; display: flex; align-items: center; gap: 8px; }
.hero .big { font-size: 68px; font-weight: 800; letter-spacing: -0.04em; line-height: 1; margin-top: 6px; font-variant-numeric: tabular-nums; }
.hero .split { color: var(--muted); font-size: 13px; margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.live { background: var(--good); box-shadow: 0 0 0 0 rgba(52,211,153,.7); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 9px rgba(52,211,153,0); } 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0); } }

/* Cartes de site */
.card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 14px 12px; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h2 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
.chip { font-size: 12px; padding: 3px 10px 3px 8px; border-radius: 99px; background: var(--surface2); color: var(--muted); display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.chip .dot { width: 7px; height: 7px; flex: 0 0 auto; margin-right: 2px; }
.chev { color: var(--muted); margin-left: 8px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { background: var(--surface2); border-radius: 14px; padding: 10px 11px 9px; min-width: 0; position: relative; overflow: hidden; }
.tile .k { color: var(--muted); font-size: 12px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.tile .v { font-size: 25px; font-weight: 750; letter-spacing: -0.03em; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.1; }
.tile .v.small { font-size: 18px; }
.tile .d { font-size: 12px; font-weight: 600; margin-top: 3px; min-height: 16px; }
.tile .d.up { color: var(--good); }
.tile .d.down { color: var(--bad); }
.tile .d.flat { color: var(--muted); }
.tile .hint { color: var(--muted); font-size: 11px; margin-top: 2px; }
.tile .age { color: var(--muted); font-size: 10.5px; margin-top: 2px; opacity: .8; }
.tile svg.spark { display: block; width: 100%; height: 22px; margin: 5px 0 1px; pointer-events: none; }

.notice { overflow-wrap: anywhere; margin-top: 10px; font-size: 13px; color: var(--muted); background: var(--surface2); border-radius: 12px; padding: 9px 11px; }
.notice.error { color: #fecaca; background: rgba(248,113,113,.12); }
.notice.warn { color: #fde68a; background: rgba(251,191,36,.10); }

/* Onglets */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface); color: var(--muted); padding: 8px 14px; border-radius: 99px; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; }
.tabs button.on { background: linear-gradient(135deg, var(--accent), #5b8cff); border-color: transparent; color: #fff; }

/* Blocs */
.block { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.block h3 { font-size: 13px; margin: 0 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }
.block .src { color: var(--muted); font-size: 11px; margin-top: 10px; opacity: .8; }
.block.unavailable { opacity: .96; }

.chart { width: 100%; height: 120px; display: block; }
.chart-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 4px; }

.bar { margin: 8px 0; }
.bar .row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.bar .row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .row span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.bar .track { height: 6px; border-radius: 4px; background: var(--surface2); margin-top: 4px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--cyan)); }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px; padding: 4px 6px 6px; }
td { padding: 7px 6px; border-top: 1px solid var(--border); vertical-align: top; max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
td:first-child, th:first-child { min-width: 76px; overflow-wrap: anywhere; }
td:not(:first-child), th:not(:first-child) { text-align: right; white-space: nowrap; }

.note { color: var(--muted); font-size: 13px; }

/* Formulaires */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type=password], input[type=number] {
  width: 100%; padding: 14px; font-size: 17px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface2); color: var(--text); outline: none;
}
input:focus { border-color: var(--accent); }
.btn { width: 100%; border: 0; padding: 14px; border-radius: 14px; font-weight: 700; font-size: 16px; color: #fff; background: linear-gradient(135deg, var(--accent), #5b8cff); cursor: pointer; }
.btn.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); font-weight: 600; }
.btn.danger { background: rgba(248,113,113,.15); color: #fecaca; border: 1px solid rgba(248,113,113,.3); }
.btn[disabled] { opacity: .55; }
.stack > * + * { margin-top: 10px; }

.login { padding-top: 14vh; }
.login h1 { font-size: 30px; letter-spacing: -0.03em; margin: 0 0 6px; }
.login p { color: var(--muted); margin: 0 0 22px; }
.err { color: #fecaca; font-size: 14px; margin: 0 0 12px; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.toggle:first-of-type { border-top: 0; }
.toggle .t { font-size: 15px; }
.toggle .s { font-size: 12px; color: var(--muted); }
.switch { position: relative; width: 52px; height: 32px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider { position: absolute; inset: 0; background: var(--surface2); border: 1px solid var(--border); border-radius: 99px; transition: .2s; }
.switch .slider::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; border-radius: 50%; background: #c8d0e4; transition: .2s; }
.switch input:checked + .slider { background: var(--accent); border-color: transparent; }
.switch input:checked + .slider::before { transform: translateX(20px); background: #fff; }
.inline { display: flex; align-items: center; gap: 10px; }
.inline input[type=number] { width: 110px; padding: 9px 10px; font-size: 16px; text-align: right; }

/* Tirer pour rafraîchir + toast */
.ptr { height: 0; overflow: hidden; display: flex; align-items: flex-end; justify-content: center; color: var(--muted); font-size: 13px; transition: height .15s; }
.ptr.pulling { transition: none; }
.toast { position: fixed; left: 16px; right: 16px; top: calc(var(--safe-top) + 8px); z-index: 20; max-width: 528px; margin: 0 auto; background: var(--surface2); border: 1px solid var(--border); border-left: 4px solid var(--good); border-radius: 14px; padding: 11px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.45); animation: drop .25s ease-out; }
.toast b { display: block; font-size: 14px; }
.toast span { color: var(--muted); font-size: 13px; }
@keyframes drop { from { transform: translateY(-14px); opacity: 0; } }

.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface), var(--surface2), var(--surface)); background-size: 200% 100%; animation: sh 1.3s infinite; margin-bottom: 12px; }
@keyframes sh { to { background-position: -200% 0; } }

.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }
