/* Objectif 9 000 € — feuille de style v2 (PWA, nuit par défaut) */

:root {
  --font: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  --bg: #10141b;
  --surface: #171d27;
  --surface-2: #202836;
  --ink: #f2f0ea;
  --ink-2: #98a1b0;
  --line: rgba(255, 255, 255, 0.09);
  --gold: #f0b84b;
  --gold-soft: rgba(240, 184, 75, 0.16);
  --gold-ink: #17120a;
  --danger: #ff6f6f;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --r-l: 22px;
  --r-m: 14px;
  --r-s: 10px;
}

html[data-theme="light"] {
  --bg: #e9edf2;
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --ink: #151a22;
  --ink-2: #5d6774;
  --line: rgba(21, 26, 34, 0.1);
  --gold: #d9a23a;
  --gold-soft: rgba(217, 162, 58, 0.18);
  --gold-ink: #1b1405;
  --danger: #d43d3d;
  --shadow: 0 14px 34px rgba(21, 26, 34, 0.1);
}

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

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body.locked { overflow: hidden; }

h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input { font-size: 16px; } /* < 16px = zoom automatique sur iPhone */

:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 6px; }

/* ------------------------------------------------------------------ */
/* Écran de verrouillage                                                */
/* ------------------------------------------------------------------ */

.lock {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #06080c;
  color: #fff;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
}

.lock[hidden] { display: none; }

.lock-halo {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(60% 45% at 78% 96%, rgba(240, 184, 75, 0.28), transparent 70%),
    radial-gradient(90% 60% at 50% 120%, rgba(48, 74, 120, 0.55), transparent 70%);
  pointer-events: none;
}

.lock-body {
  position: relative;
  width: min(100%, 360px);
  padding: 24px;
  text-align: center;
}

.lock-title {
  font-size: 22px;
  font-weight: 500;
  margin-bottom: 26px;
  letter-spacing: 0.01em;
}

.lock-dots {
  display: flex;
  justify-content: center;
  gap: 22px;
  height: 14px;
  margin-bottom: 14px;
}

.lock-dots span {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  transition: background 0.12s ease;
}

.lock-dots span.filled { background: #fff; }

.lock-dots.shake { animation: shake 0.45s ease; }

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(5px); }
  30%, 50%, 70% { transform: translateX(-9px); }
  40%, 60% { transform: translateX(9px); }
}

.lock-hint {
  min-height: 22px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 34px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 78px);
  gap: 18px 26px;
  justify-content: center;
}

.keypad button {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.13);
  border: 1px solid rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.1s ease, transform 0.1s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.keypad button:active { background: rgba(255, 255, 255, 0.42); transform: scale(0.96); }

.keypad button b { font-size: 33px; font-weight: 500; }

.keypad button i {
  font-style: normal;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  margin-top: 3px;
  opacity: 0.9;
}

.keypad .key-text {
  background: none;
  border: 0;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  font-size: 17px;
  font-weight: 400;
}

.keypad .key-text:active { background: none; transform: none; opacity: 0.6; }

.lock.denied .keypad { pointer-events: none; opacity: 0.35; }

/* ------------------------------------------------------------------ */
/* Application                                                          */
/* ------------------------------------------------------------------ */

.app {
  width: min(100%, 540px);
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
}

.app[hidden] { display: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 4px;
}

.topbar h1 { font-size: 17px; font-weight: 600; color: var(--ink-2); }
.topbar h1 span { color: var(--ink); }

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
}

.icon-btn .ico-sun { display: none; }
html[data-theme="light"] .icon-btn .ico-sun { display: block; }
html[data-theme="light"] .icon-btn .ico-moon { display: none; }

.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Bilan */

.hero { padding: 26px 0 8px; }

.hero-total {
  font-size: clamp(60px, 19vw, 84px);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.hero-unit { font-size: 0.42em; font-weight: 700; letter-spacing: 0; }

.hero-sub { margin-top: 10px; font-size: 17px; color: var(--ink-2); }
.hero-sub b { color: var(--ink); font-weight: 600; }

.lights {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 26px 0 10px;
  min-height: 12px;
}

.lights i, .dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.lights i.on, .dot.on {
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: 0 0 10px rgba(240, 184, 75, 0.45);
}

.lights i.today {
  border-color: var(--gold);
  border-width: 2px;
  background: transparent;
}

.lights .more { font-size: 12px; color: var(--ink-2); align-self: center; margin-left: 4px; }

.lights-legend[hidden] { display: none; }
.lights-legend { font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.lights-legend .dot { width: 9px; height: 9px; box-shadow: none; }
.lights-legend .dot + span, .lights-legend span + .dot { margin-left: 4px; }

.figures {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 18px;
}

.figures > div {
  padding: 12px 10px;
  border-radius: var(--r-m);
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  gap: 2px;
}

.figures b { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.figures span { font-size: 12px; line-height: 1.25; color: var(--ink-2); }

.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.week-label { font-size: 15px; font-weight: 600; text-align: center; flex: 1; line-height: 1.3; }
.week-label small { display: block; font-weight: 500; color: var(--ink-2); font-size: 13px; }

.week-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 24px;
  line-height: 1;
  display: grid;
  place-items: center;
  padding-bottom: 3px;
}

.week-btn:active { background: var(--gold-soft); }

.cancel-edit { display: block; margin: 12px auto 0; }
.cancel-edit[hidden] { display: none; }

.add.editing { outline: 2px solid var(--gold); outline-offset: 0; }

.forecast {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.forecast-label { font-size: 14px; color: var(--ink-2); }
.forecast-date { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; margin-top: 2px; }
.forecast-date.done { color: var(--gold); }
.forecast-meta { font-size: 14px; color: var(--ink-2); margin-top: 4px; }

/* Saisie */

.add {
  margin-top: 24px;
  padding: 18px;
  background: var(--surface);
  border-radius: var(--r-l);
  box-shadow: var(--shadow);
}

.add-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.add-head h2 { font-size: 18px; font-weight: 700; }

.link-btn {
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
  text-decoration: none;
  padding: 4px 0;
}

.add-date {
  width: 100%;
  margin-bottom: 12px;
}

.add-date[hidden] { display: none; }

.add-row { display: flex; gap: 10px; }

.amount-field {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  min-height: 60px;
}

.amount-field:focus-within { border-color: var(--gold); }

.amount-field input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  outline: 0;
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

.amount-field input::-webkit-outer-spin-button,
.amount-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.amount-field span { font-size: 22px; font-weight: 700; color: var(--ink-2); }

.btn-primary {
  flex: 0 0 auto;
  padding: 0 20px;
  min-height: 60px;
  border-radius: var(--r-m);
  background: var(--gold);
  color: var(--gold-ink);
  font-weight: 700;
  font-size: 16px;
  transition: transform 0.1s ease, opacity 0.1s ease;
}

.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.55; }

.add-note, .add-date, .field-input input, .vacation-row input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: var(--r-s);
  background: var(--surface-2);
  border: 1px solid var(--line);
  outline: 0;
  -webkit-appearance: none;
  appearance: none;
}

.add-note { margin-top: 10px; }
.add-note:focus, .add-date:focus, .field-input input:focus, .vacation-row input:focus { border-color: var(--gold); }

input[type="date"] { min-width: 0; color-scheme: dark; }
html[data-theme="light"] input[type="date"] { color-scheme: light; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }

/* Historique */

.history { margin-top: 30px; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.section-head h2 { font-size: 20px; font-weight: 700; }
.section-head.compact { margin-bottom: 8px; }
.section-head.compact h3 { font-size: 15px; font-weight: 600; }

.empty { color: var(--ink-2); font-size: 15px; padding: 12px 0; }
.empty[hidden] { display: none; }

.month { margin-top: 18px; }

.month-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  color: var(--ink-2);
}

.month-head b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.entry {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.entry-week { min-width: 0; line-height: 1.2; }
.entry-week b { display: block; font-size: 15px; font-weight: 700; }
.entry-week span { display: block; font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.entry-edit {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  display: inline-grid;
  place-items: center;
}

.entry-edit svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.entry-amount { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 17px; white-space: nowrap; }

.entry-del {
  height: 36px;
  min-width: 36px;
  padding: 0 8px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.entry-del svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.entry-del.armed {
  padding: 0 14px;
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.history-help { font-size: 13px; color: var(--ink-2); margin: 4px 0 6px; }

/* Réglages */

.settings { margin-top: 30px; }

details > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 6px 0;
}

details > summary::-webkit-details-marker { display: none; }
details > summary h2 { font-size: 20px; font-weight: 700; }

.chev {
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--ink-2);
  border-bottom: 2px solid var(--ink-2);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  margin-right: 4px;
}

details[open] .chev { transform: rotate(-135deg); }

.settings-body { padding-top: 12px; display: grid; gap: 16px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.field-input { position: relative; display: flex; align-items: center; }
.field-input b { position: absolute; right: 14px; color: var(--ink-2); }

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  cursor: pointer;
}

.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch i {
  flex: 0 0 auto;
  width: 50px;
  height: 30px;
  border-radius: 15px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  position: relative;
  transition: background 0.15s ease;
}

.switch i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease;
}

.switch input:checked + i { background: var(--gold); border-color: var(--gold); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2px solid var(--gold); outline-offset: 2px; }

.vacations { padding-top: 4px; }
.vacation-list { display: grid; gap: 8px; }

.vacation-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr 34px;
  align-items: center;
  gap: 8px;
}

.vacation-row input { padding-left: 8px; padding-right: 8px; }

.vac-sep { font-size: 13px; color: var(--ink-2); }

.remove-vac {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 20px;
  color: var(--ink-2);
  display: grid;
  place-items: center;
}

.help { font-size: 13px; color: var(--ink-2); margin-top: 10px; }

.danger { padding-top: 10px; border-top: 1px solid var(--line); }

.btn-danger {
  width: 100%;
  min-height: 46px;
  border-radius: var(--r-s);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-weight: 600;
}

.btn-danger.armed { background: var(--danger); color: #fff; }

.footer-note { margin-top: 34px; font-size: 12.5px; color: var(--ink-2); text-align: center; }

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 60;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 360px) {
  .keypad { grid-template-columns: repeat(3, 70px); gap: 14px 20px; }
  .keypad button { width: 70px; height: 70px; }
  .vacation-row { grid-template-columns: 1fr 34px; }
  .vac-sep { display: none; }
  .vacation-row .remove-vac { grid-row: 1 / span 2; grid-column: 2; }
}

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