
:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --surface: #fff;
  --text: #202127;
  --muted: #858791;
  --line: #e9e9ed;
  --accent: #f47b35;
  --accent-soft: #fff0e7;
  --success: #35a873;
  --danger: #d84d4d;
  --shadow: 0 4px 18px rgba(25, 25, 35, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  min-height: 100%;
}

html { background: #ececf0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: #ececf0;
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.app-shell {
  width: 100%;
  max-width: 430px;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--bg);
  box-shadow: 0 0 35px #19192312;
}

.topbar {
  flex: 0 0 auto;
  min-height: 76px;
  padding: max(14px, env(safe-area-inset-top)) 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.4px;
}

.topbar h1 {
  margin: 0;
  font-size: 25px;
  letter-spacing: -.8px;
  line-height: 1.1;
}

.topbar h1 span { color: var(--accent); }

.avatar {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}

#app-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  padding: 18px 16px 26px;
  -webkit-overflow-scrolling: touch;
}

.page { display: none; animation: fade-in .16s ease-out; }
.page.active { display: block; }

@keyframes fade-in {
  from { opacity: .65; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

.welcome { padding: 3px 2px 20px; }
.welcome h2, .page-heading h2 {
  margin: 0 0 8px;
  font-size: 25px;
  line-height: 1.2;
  letter-spacing: -.7px;
}
.welcome p, .page-heading p { line-height: 1.5; }
.welcome .muted, .page-heading .muted { margin: 0; }
.muted { color: var(--muted); font-size: 13px; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.summary-card {
  min-width: 0;
  min-height: 112px;
  padding: 15px;
  display: block;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}
button.summary-card { cursor: pointer; }

.summary-label {
  display: block;
  margin-bottom: 13px;
  color: var(--muted);
  font-size: 12px;
}

.summary-card strong {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -.6px;
  overflow-wrap: anywhere;
}
.summary-card small { margin-left: 5px; color: var(--muted); font-size: 11px; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 25px 1px 13px;
}
.section-heading h3, .panel h3 { margin: 0; font-size: 16px; }
.section-heading > span { font-size: 11px; }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.feature-card {
  min-width: 0;
  min-height: 140px;
  padding: 15px 13px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.feature-card:active { transform: scale(.98); }
.feature-card img { width: 37px; height: 37px; margin-bottom: 13px; object-fit: contain; }
.feature-card span { font-size: 14px; font-weight: 750; }
.feature-card small { margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.35; }

.panel, .calendar-panel {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  min-width: 0;
}

.page-heading { padding: 3px 1px 12px; }
.page-heading h2 { margin-bottom: 7px; }
.page-heading .eyebrow { margin-bottom: 9px; }

.panel label, .import-label {
  display: block;
  margin: 15px 0 8px;
  font-size: 12px;
  font-weight: 700;
}
.panel label:first-child { margin-top: 0; }

.panel input:not([type="checkbox"]), #import-file {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

.primary-button, .secondary-button, .danger-button {
  width: 100%;
  min-height: 47px;
  margin-top: 17px;
  padding: 12px 14px;
  border: 0;
  border-radius: 13px;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}
.primary-button { color: #fff; background: var(--accent); }
.secondary-button { color: var(--text); background: var(--accent-soft); }
.danger-button { color: #fff; background: var(--danger); }

.progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 650;
}
.progress-top strong { color: var(--accent); font-size: 13px; }
.progress-track { height: 8px; margin-top: 13px; overflow: hidden; border-radius: 20px; background: var(--line); }
.progress-fill { width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .25s ease; }
.panel > p { line-height: 1.45; }

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.setting-row p { margin-bottom: 0; line-height: 1.45; }
.switch { position: relative; display: inline-flex; width: 46px; height: 27px; flex-shrink: 0; margin: 0 !important; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-track { position: absolute; inset: 0; border-radius: 30px; background: #d7d7de; cursor: pointer; transition: background .2s; }
.switch-track::before { content: ""; position: absolute; width: 21px; height: 21px; left: 3px; top: 3px; border-radius: 50%; background: white; box-shadow: 0 1px 4px #0002; transition: transform .2s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::before { transform: translateX(19px); }

.footer-note { margin: 25px 0 8px; color: var(--muted); font-size: 11px; text-align: center; }
#import-file { margin-top: 0; font-size: 12px; }

/* Calendriers */
.calendar-panel { padding: 14px; }
.calendar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}
.calendar-title-row h3 { margin: 0; font-size: 16px; }
.calendar-nav { display: flex; align-items: center; gap: 6px; }
.calendar-nav button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.calendar-today {
  width: auto !important;
  padding: 0 9px;
  font-size: 11px !important;
}
.calendar-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-bottom: 13px;
}
.calendar-controls select, .calendar-controls input {
  width: 100%;
  min-width: 0;
  height: 39px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
}
.calendar-weekdays, .calendar-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}
.calendar-weekdays { margin-bottom: 5px; }
.calendar-weekdays span {
  padding: 5px 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}
.calendar-day {
  position: relative;
  min-width: 0;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 2px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
}
.calendar-day.empty { pointer-events: none; }
.calendar-day.selected { border-color: var(--accent); background: var(--accent-soft); font-weight: 800; }
.calendar-day.today { box-shadow: inset 0 0 0 1px var(--accent); }
.calendar-day.has-data::after {
  content: "";
  width: 5px;
  height: 5px;
  flex: 0 0 5px;
  border-radius: 50%;
  background: var(--success);
}
.calendar-day.no-data::after {
  content: "";
  width: 5px;
  height: 5px;
  flex: 0 0 5px;
  border-radius: 50%;
  background: var(--line);
}
.calendar-day.selected::after { background: var(--accent); }
.calendar-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; color: var(--muted); font-size: 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.legend-dot.empty-dot { background: #bfc0c8; }
.calendar-summary {
  margin-top: 15px;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg);
}
.calendar-summary strong { font-size: 13px; }
.calendar-summary p { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.period-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; margin-top: 14px; }
.period-tab {
  min-width: 0;
  min-height: 34px;
  padding: 5px 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}
.period-tab.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.period-summary { margin-top: 12px; font-size: 12px; line-height: 1.5; }
.period-list { display: grid; gap: 7px; margin-top: 10px; }
.period-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 11px; }
.period-item span:first-child { min-width: 0; }
.period-item strong { flex-shrink: 0; text-align: right; }
.period-empty { padding: 12px 0; color: var(--muted); font-size: 12px; text-align: center; }

.bottom-nav {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  padding: 9px 5px max(9px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
  z-index: 5;
}
.nav-item {
  min-width: 0;
  min-height: 53px;
  padding: 4px 2px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.nav-item img { display: block; width: 21px; height: 21px; object-fit: contain; opacity: .65; }
.nav-item span { max-width: 100%; overflow: hidden; font-size: 10px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.active { color: var(--accent); background: var(--accent-soft); }
.nav-item.active img { opacity: 1; }

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: calc(85px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: min(390px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 12px;
  color: white;
  background: #25252c;
  font-size: 12px;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

body.dark {
  color-scheme: dark;
  --bg: #15151a;
  --surface: #202027;
  --text: #f3f3f6;
  --muted: #a2a2ad;
  --line: #33333d;
  --accent: #ff914d;
  --accent-soft: #38271f;
  --success: #4bc58a;
  --shadow: 0 4px 18px #0002;
}
body.dark, body.dark html { background: #101015; }
body.dark .topbar, body.dark .bottom-nav, body.dark .summary-card,
body.dark .feature-card, body.dark .panel, body.dark .calendar-panel {
  background: var(--surface);
}
body.dark .panel input:not([type="checkbox"]),
body.dark #import-file,
body.dark .calendar-controls select,
body.dark .calendar-controls input,
body.dark .calendar-nav button,
body.dark .calendar-day,
body.dark .period-tab {
  color: var(--text);
  background: var(--bg);
}
body.dark .calendar-day.selected,
body.dark .period-tab.active { background: var(--accent-soft); }
body.dark .calendar-summary { background: var(--bg); }
body.dark .nav-item.active { background: var(--accent-soft); }

/* Sur ordinateur : le site conserve une largeur de téléphone. */
@media (min-width: 431px) {
  .app-shell { width: 430px; max-width: 100%; }
}

/* Petits téléphones */
@media (max-width: 360px) {
  #app-main { padding: 14px 12px 22px; }
  .topbar { padding-right: 14px; padding-left: 14px; }
  .summary-card, .feature-card { padding: 12px; }
  .calendar-panel { padding: 10px; }
  .calendar-days, .calendar-weekdays { gap: 2px; }
  .calendar-day { border-radius: 7px; font-size: 10px; }
  .nav-item span { font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
