/* ---------------------------------------------------------------- Tokens */
:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: rgba(11, 11, 11, 0.1);
  --grid: #e1e0d9;
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.1);
  --good: #0ca30c;
  --good-strong: #006300;
  --good-wash: rgba(12, 163, 12, 0.12);
  --bad: #d03b3b;
  --bad-wash: rgba(208, 59, 59, 0.1);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 4px 16px rgba(11, 11, 11, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hairline: rgba(255, 255, 255, 0.1);
    --grid: #2c2c2a;
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --good: #0ca30c;
    --good-strong: #0ca30c;
    --good-wash: rgba(12, 163, 12, 0.18);
    --bad: #d03b3b;
    --bad-wash: rgba(208, 59, 59, 0.18);
    --shadow: none;
  }
}

/* ---------------------------------------------------------------- Base */
* {
  box-sizing: border-box;
}
html {
  height: 100%;
}
body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
input,
select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
h1,
h2,
h3 {
  margin: 0;
}

.app {
  max-width: 460px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.icon-btn {
  background: none;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 18px;
  color: var(--ink-2);
}
.icon-btn:hover {
  background: var(--accent-wash);
}

/* ---------------------------------------------------------------- Suivi */
.treatment-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
}
.treatment-row select {
  flex: 1;
  font-weight: 600;
}
.treatment-period {
  margin: 6px 2px 14px;
  font-size: 13px;
  color: var(--muted);
}
.badge-archived {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  border: 1px solid var(--grid);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 6px;
}

/* ---------------------------------------------------------------- Bouton de prise */
.take-note {
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
  text-align: center;
}

/* ---------------------------------------------------------------- Stats */
.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 20px 2px 8px;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 10px;
  text-align: center;
}
.stat .value {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.15;
}
.stat .label {
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 2px;
}

/* ---------------------------------------------------------------- Rappel boîte */
.box-alert {
  background: var(--accent-wash);
  color: var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 14px;
}

.box-alert.low {
  background: var(--bad-wash);
  color: var(--bad);
}

/* ---------------------------------------------------------------- Calendrier */
.calendar {
  padding: 14px;
}
.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.cal-head .month {
  font-size: 16px;
  font-weight: 700;
  text-transform: capitalize;
}
.cal-nav {
  background: none;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  color: var(--ink-2);
}
.cal-nav:disabled {
  opacity: 0.35;
  cursor: default;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  padding: 4px 0;
}
.cal-day {
  aspect-ratio: 1 / 1.05;
  border: none;
  border-radius: 10px;
  background: none;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0;
  padding: 0;
  font-variant-numeric: tabular-nums;
}
.cal-day .n {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
}
.cal-day .m {
  font-size: 9px;
  line-height: 1;
  height: 10px;
}
.cal-day.out {
  visibility: hidden;
}
.cal-day.off .n {
  color: var(--muted);
  opacity: 0.45;
  font-weight: 400;
}
.cal-day.off {
  cursor: default;
}
.cal-day.taken {
  background: var(--good);
  color: #fff;
}
.cal-day.missed {
  background: var(--bad-wash);
  color: var(--bad);
}
.cal-day.pending {
  box-shadow: inset 0 0 0 2px var(--accent);
  color: var(--accent);
}
.cal-day.today .n {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.cal-legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--ink-2);
}
.cal-legend .k {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.dot {
  width: 14px;
  height: 14px;
  border-radius: 5px;
  display: inline-grid;
  place-items: center;
  font-size: 9px;
  line-height: 1;
}
.dot.taken {
  background: var(--good);
  color: #fff;
}
.dot.missed {
  background: var(--bad-wash);
  color: var(--bad);
}
.dot.pending {
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* ---------------------------------------------------------------- Boutons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  width: 100%;
}
.btn:hover {
  filter: brightness(1.06);
}
.btn.secondary {
  background: none;
  color: var(--ink-2);
  border: 1px solid var(--grid);
}
.btn.danger {
  background: none;
  color: var(--bad);
  border: 1px solid var(--grid);
}

/* ---------------------------------------------------------------- Dialog réglages */
dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  max-height: 85vh;
  margin: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}
.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 0;
}
.dlg-head h2 {
  font-size: 18px;
}
.dlg-body {
  padding: 8px 18px 18px;
}
.dlg-section {
  border-top: 1px solid var(--grid);
  padding: 14px 0;
}
.dlg-section:first-child {
  border-top: none;
}
.dlg-section h3 {
  font-size: 14px;
  margin-bottom: 8px;
}
.field-label {
  display: block;
  font-size: 13px;
  color: var(--ink-2);
  margin: 8px 0 4px;
}

/* ---------------------------------------------------------------- Login */
.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: min(380px, 100%);
  text-align: center;
  padding: 28px 22px;
}
.login-card .logo {
  width: 64px;
  height: 64px;
  margin-bottom: 10px;
}
.login-card h1 {
  font-size: 22px;
  margin-bottom: 2px;
}
.login-card .sub {
  color: var(--ink-2);
  font-size: 14px;
  margin: 0 0 18px;
}
.login-card form {
  display: grid;
  gap: 10px;
  text-align: left;
}
.error {
  color: var(--bad);
  font-size: 14px;
  min-height: 20px;
  margin: 6px 0 0;
  text-align: center;
}

/* ---------------------------------------------------------------- Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--page);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  max-width: calc(100vw - 40px);
}
.toast.show {
  opacity: 1;
}

.hidden {
  display: none !important;
}
