/* ---------- Thèmes ---------- */
:root {
  --bg: #eef3fb;
  --bg-2: #e3ebf7;
  --surface: rgba(255, 255, 255, .82);
  --surface-solid: #ffffff;
  --surface-2: #e8eef8;
  --border: rgba(20, 50, 110, .09);
  --text: #0f1b2d;
  --muted: #5f6d85;
  --accent: #2563eb;
  --accent-2: #4f8dff;
  --accent-soft: rgba(37, 99, 235, .11);
  --on-accent: #ffffff;
  --danger: #d4483f;
  --shadow: 0 1px 2px rgba(20, 50, 110, .05), 0 10px 28px rgba(20, 50, 110, .08);
  --glow-1: rgba(79, 141, 255, .30);
  --glow-2: rgba(56, 200, 230, .20);
  --ring-bg: radial-gradient(circle at 50% 40%, #9cc4ff, #4f8dff 55%, #2457d6);
  --ring-text: #ffffff;
  --ring-track: rgba(255, 255, 255, .25);
  --radius: 22px;
  --radius-sm: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0c12;
    --bg-2: #10131c;
    --surface: rgba(255, 255, 255, .045);
    --surface-solid: #151925;
    --surface-2: rgba(255, 255, 255, .06);
    --border: rgba(255, 255, 255, .08);
    --text: #eef0f6;
    --muted: #8b91a3;
    --accent: #f0b54c;
    --accent-2: #ffcf7a;
    --accent-soft: rgba(240, 181, 76, .14);
    --on-accent: #1a1204;
    --danger: #ff6b62;
    --shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 12px 32px rgba(0, 0, 0, .35);
    --glow-1: rgba(240, 181, 76, .16);
    --glow-2: rgba(90, 110, 255, .16);
    --ring-bg: radial-gradient(circle at 50% 40%, #ffd98a, #f0a83a 55%, #d9822b);
    --ring-text: #1a1204;
    --ring-track: rgba(26, 18, 4, .12);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0c12;
  --bg-2: #10131c;
  --surface: rgba(255, 255, 255, .045);
  --surface-solid: #151925;
  --surface-2: rgba(255, 255, 255, .06);
  --border: rgba(255, 255, 255, .08);
  --text: #eef0f6;
  --muted: #8b91a3;
  --accent: #f0b54c;
  --accent-2: #ffcf7a;
  --accent-soft: rgba(240, 181, 76, .14);
  --on-accent: #1a1204;
  --danger: #ff6b62;
  --shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 12px 32px rgba(0, 0, 0, .35);
  --glow-1: rgba(240, 181, 76, .16);
  --glow-2: rgba(90, 110, 255, .16);
  --ring-bg: radial-gradient(circle at 50% 40%, #ffd98a, #f0a83a 55%, #d9822b);
  --ring-text: #1a1204;
  --ring-track: rgba(26, 18, 4, .12);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding: 0 16px calc(96px + env(safe-area-inset-bottom));
  transition: background-color .3s, color .3s;
}
main, .top { max-width: 880px; margin: 0 auto; position: relative; }

.bg-glow {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(60vmax 40vmax at 15% -10%, var(--glow-1), transparent 60%),
    radial-gradient(50vmax 40vmax at 110% 10%, var(--glow-2), transparent 60%);
}
main, .top { z-index: 1; }

h1 { font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 1.1rem; font-weight: 650; letter-spacing: -.01em; margin: 0; }
.muted { color: var(--muted); }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .fill { fill: currentColor; stroke: none; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 10px 16px; border-radius: 999px; font: inherit; font-weight: 550; font-size: .95rem;
  cursor: pointer; white-space: nowrap; transition: transform .12s, background-color .2s, box-shadow .2s, filter .2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: var(--on-accent); border-color: transparent;
  box-shadow: 0 6px 18px var(--accent-soft);
}
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 14px; font-size: .85rem; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; display: inline-grid; place-items: center;
  border: 0; background: transparent; color: var(--muted); cursor: pointer; transition: background-color .2s, color .2s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------- En-tête ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) 0 16px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: var(--on-accent);
}
.logo svg { width: 20px; height: 20px; }
.top-actions { display: flex; align-items: center; gap: 10px; }

.segmented {
  display: inline-flex; padding: 4px; gap: 2px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); backdrop-filter: blur(12px);
}
.segmented button {
  width: 34px; height: 30px; border-radius: 999px; border: 0; background: transparent;
  color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: .2s;
}
.segmented button svg { width: 17px; height: 17px; }
.segmented button[aria-checked="true"] { background: var(--surface-solid); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }

.segmented.wide { display: flex; width: 100%; margin-top: 8px; }
.segmented.wide label { flex: 1; margin: 0; }
.segmented.wide input { position: absolute; opacity: 0; pointer-events: none; }
.segmented.wide span {
  display: block; text-align: center; padding: 8px 10px; border-radius: 999px;
  color: var(--muted); cursor: pointer; font-weight: 550; font-size: .92rem; transition: .2s;
}
.segmented.wide input:checked + span { background: var(--surface-solid); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.segmented.wide input:focus-visible + span { outline: 2px solid var(--accent); }

/* ---------- Horloge ---------- */
.hero {
  text-align: center; padding: 40px 16px 32px; margin-bottom: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 28px;
  box-shadow: var(--shadow); backdrop-filter: blur(20px);
}
.clock {
  display: inline-flex; align-items: flex-start; gap: 6px;
  font-size: clamp(4.5rem, 20vw, 9rem); font-weight: 200; line-height: .95;
  letter-spacing: -.045em; font-variant-numeric: tabular-nums;
}
.clock .sec {
  font-size: .22em; font-weight: 400; letter-spacing: 0; color: var(--muted);
  margin-top: .6em; min-width: 2ch; text-align: left;
}
.date { color: var(--muted); margin-top: 10px; text-transform: capitalize; font-size: 1.02rem; }
.next-pill {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 22px;
  padding: 9px 16px; border-radius: 999px; max-width: 100%;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: .95rem;
}
.next-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.next-pill svg { width: 17px; height: 17px; }
.status { margin-top: 12px; font-size: .85rem; color: var(--muted); min-height: 1.2em; }
.status.warn { color: var(--danger); }

/* ---------- Sections ---------- */
.section { margin-bottom: 28px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 0 4px 14px; }
.count {
  display: inline-block; margin-left: 6px; padding: 1px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: .8rem; font-weight: 600; vertical-align: 2px;
}
.count:empty { display: none; }

/* ---------- Cartes sonneries ---------- */
.alarm-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px;
}
.alarm {
  position: relative; padding: 18px 18px 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  backdrop-filter: blur(16px); transition: opacity .25s, transform .2s;
}
.alarm.off { opacity: .5; }
.alarm .top-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.alarm .time { font-size: 2.6rem; font-weight: 250; line-height: 1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.alarm .name { font-weight: 650; margin-top: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alarm .sched { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.alarm .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: .78rem; font-weight: 550;
}
.tag svg { width: 13px; height: 13px; }
.dots { display: flex; gap: 4px; margin-top: 12px; }
.dots i {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-style: normal; font-size: .7rem; font-weight: 650; color: var(--muted); background: var(--surface-2);
}
.dots i.on { background: var(--accent-soft); color: var(--accent); }
.alarm .btns { display: flex; justify-content: flex-end; gap: 2px; margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }

.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 30px; transition: .25s; }
.switch span::before {
  content: ""; position: absolute; width: 24px; height: 24px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; box-shadow: 0 2px 6px rgba(0,0,0,.2); transition: transform .25s cubic-bezier(.3,1.4,.5,1);
}
.switch input:checked + span { background: linear-gradient(135deg, var(--accent-2), var(--accent)); border-color: transparent; }
.switch input:checked + span::before { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.empty {
  text-align: center; padding: 36px 16px; border-radius: var(--radius);
  border: 1.5px dashed var(--border); color: var(--text);
}
.empty svg { width: 34px; height: 34px; color: var(--accent); }
.empty p { margin: 8px 0 0; }

/* ---------- Timeline ---------- */
.timeline {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 8px 18px; backdrop-filter: blur(16px);
}
.tl-day { padding: 12px 0; border-top: 1px solid var(--border); }
.tl-day:first-child { border-top: 0; }
.tl-day h3 { margin: 0 0 8px; font-size: .78rem; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.tl-day h3 .today { color: var(--accent); }
.tl-item { display: flex; align-items: center; gap: 12px; padding: 5px 0; }
.tl-item::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; box-shadow: 0 0 0 4px var(--accent-soft); }
.tl-item .t { font-variant-numeric: tabular-nums; font-weight: 650; min-width: 48px; }
.tl-item .l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline .none { color: var(--muted); padding: 14px 0; text-align: center; }

/* ---------- Éditeur ---------- */
dialog {
  background: var(--surface-solid); color: var(--text); border: 1px solid var(--border);
  border-radius: 28px; padding: 22px; width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
dialog[open] { animation: pop .25s cubic-bezier(.2,.9,.3,1.2); }
dialog::backdrop { background: rgba(5, 6, 10, .45); backdrop-filter: blur(6px); }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.sheet-handle { display: none; }
dialog h2 { text-align: center; color: var(--muted); font-size: .9rem; font-weight: 600; }

.time-input {
  display: block; width: 100%; margin: 10px 0 18px; padding: 6px; text-align: center;
  font: inherit; font-size: 3.4rem; font-weight: 250; letter-spacing: -.03em; font-variant-numeric: tabular-nums;
  background: transparent; color: var(--text); border: 0; border-radius: var(--radius-sm);
}
.time-input:focus { outline: none; background: var(--surface-2); }

.field { display: block; margin-bottom: 16px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.field-row { display: flex; justify-content: space-between; }
.field-row b { color: var(--text); }
input[type=text], input[type=date], select {
  display: block; width: 100%; margin-top: 7px; padding: 12px 14px; font: inherit; font-weight: 450;
  background: var(--surface-2); color: var(--text); border: 1px solid transparent; border-radius: var(--radius-sm);
  transition: border-color .2s, box-shadow .2s; -webkit-appearance: none; appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b91a3' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; padding-right: 38px;
}
input[type=text]:focus, input[type=date]:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

input[type=range] { width: 100%; margin-top: 12px; accent-color: var(--accent); }

.days { display: flex; justify-content: space-between; gap: 6px; margin-bottom: 18px; }
.days label { margin: 0; flex: 1; }
.days input { position: absolute; opacity: 0; pointer-events: none; }
.days span {
  display: grid; place-items: center; aspect-ratio: 1; max-width: 48px; margin: 0 auto; border-radius: 50%;
  background: var(--surface-2); color: var(--muted); font-weight: 650; cursor: pointer; transition: .2s;
}
.days input:checked + span { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: var(--on-accent); }
.days input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.row input { margin-top: 0; }
.chips { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; }
.chips li {
  background: var(--accent-soft); color: var(--accent); border-radius: 999px;
  padding: 5px 6px 5px 12px; display: flex; gap: 4px; align-items: center; font-size: .88rem; font-weight: 600;
}
.chips button { background: none; border: 0; color: inherit; cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0 4px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.spacer { flex: 1; }

/* ---------- Sonnerie ---------- */
.ringing {
  position: fixed; inset: 0; z-index: 50; padding: 24px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; text-align: center;
  color: var(--ring-text);
  background: var(--ring-bg);
  animation: breathe 2.4s ease-in-out infinite;
}
@keyframes breathe { 50% { filter: brightness(.9) saturate(1.1); } }
.ring-wrap { position: relative; width: min(72vw, 340px); aspect-ratio: 1; }
.ring-wrap::before, .ring-wrap::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(255,255,255,.6);
  animation: ripple 2.4s ease-out infinite;
}
.ring-wrap::after { animation-delay: 1.2s; }
@keyframes ripple { from { transform: scale(.85); opacity: .9; } to { transform: scale(1.35); opacity: 0; } }
.ring-progress { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-progress circle { fill: none; stroke-width: 5; }
.ring-progress .track { stroke: var(--ring-track); }
.ring-progress .bar { stroke: currentColor; stroke-linecap: round; stroke-dasharray: 339.3; transition: stroke-dashoffset 1s linear; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-time { font-size: clamp(3rem, 15vw, 5.5rem); font-weight: 200; letter-spacing: -.04em; font-variant-numeric: tabular-nums; line-height: 1; }
.ring-count { margin-top: 8px; font-weight: 600; opacity: .7; font-variant-numeric: tabular-nums; }
.ring-label { font-size: clamp(1.8rem, 7vw, 3rem); font-weight: 700; letter-spacing: -.02em; }
.ring-hint { font-size: .9rem; opacity: .65; }

/* ---------- Mode Shabbat ---------- */
body.shabbat .editable .btns,
body.shabbat #addBtn,
body.shabbat .switch,
body.shabbat .top-actions { display: none; }
body.shabbat .hero { padding: 64px 16px 48px; }
body.shabbat.dim main, body.shabbat.dim .top, body.shabbat.dim .lockbar { filter: brightness(.45); }
.lockbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 40;
  max-width: 600px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px 8px 8px 16px; border-radius: 999px;
  background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: .88rem; color: var(--muted);
}
.lock-info { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.lock-info svg { width: 16px; height: 16px; color: var(--accent); }
#unlockBtn { position: relative; overflow: hidden; }
#unlockBtn > span:last-child { position: relative; }
.hold-fill { position: absolute; inset: 0; width: 0; background: var(--danger); opacity: .85; }
#unlockBtn.holding { color: #fff; }
#unlockBtn.holding .hold-fill { width: 100%; transition: width 3s linear; }

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
  .top { flex-wrap: wrap; }
  .top-actions { width: 100%; justify-content: space-between; }
  .next-pill { border-radius: 16px; text-align: left; }
  .next-pill span { white-space: normal; }
  .brand h1 { font-size: 1rem; }
  .hero { padding: 32px 12px 26px; border-radius: 24px; }
  .grid2 { grid-template-columns: 1fr; gap: 0; }
  .alarm-grid { grid-template-columns: 1fr; }
  dialog {
    width: 100%; max-width: 100%; max-height: 92vh; overflow-x: hidden; margin: auto 0 0; border-radius: 28px 28px 0 0;
    padding: 12px 18px calc(18px + env(safe-area-inset-bottom));
  }
  dialog[open] { animation: slideUp .3s cubic-bezier(.2,.9,.3,1); }
  @keyframes slideUp { from { transform: translateY(100%); } }
  .sheet-handle { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 12px; }
  .lock-info { font-size: .8rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
