:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #1f2a27;
  --muted: #66716d;
  --border: #e3ddd3;
  --primary: #2f6f5e;
  --primary-text: #ffffff;
  --start: #2f8f5b;
  --stop: #c4513b;
  --ok-bg: #e2f1e8;
  --ok-text: #22603f;
  --live-bg: #fdf0d9;
  --live-text: #8a5a00;
  --error-bg: #fbe5e1;
  --error-text: #9b2c1a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(31, 42, 39, 0.06), 0 4px 14px rgba(31, 42, 39, 0.06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a18;
    --surface: #1d2522;
    --text: #e9efec;
    --muted: #9aa7a2;
    --border: #2d3834;
    --primary: #5fb39b;
    --primary-text: #0d1513;
    --start: #3fae72;
    --stop: #c9573f;
    --ok-bg: #1f3a2c;
    --ok-text: #9fdcb8;
    --live-bg: #3a2f17;
    --live-text: #f2c879;
    --error-bg: #42221c;
    --error-text: #f4a898;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
  color: var(--primary);
}

h1 {
  font-size: 1.5rem;
  margin: 0.5rem 0 1rem;
}

h2 {
  font-size: 1.1rem;
  margin: 0;
}

.wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

/* --- Barre du haut --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

.tabs {
  display: flex;
  gap: 2px;
}

.tabs a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

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

.tabs a[aria-current="page"] {
  background: var(--bg);
  color: var(--primary);
  font-weight: 600;
}

/* Téléphone : barre d'onglets en bas, à portée de pouce. */
@media (max-width: 600px) {
  .topbar {
    justify-content: center;
  }

  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    gap: 0;
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }

  .tabs a {
    flex: 1;
    flex-direction: column;
    gap: 2px;
    padding: 6px 4px;
    font-size: 0.75rem;
  }

  .tabs svg {
    width: 24px;
    height: 24px;
  }

  .tabs a[aria-current="page"] {
    background: transparent;
  }

  .tabs a[aria-current="page"] svg {
    stroke-width: 2.2;
  }

  .has-tabs .wrap {
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }
}

/* --- Blocs --- */

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

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.hero {
  text-align: center;
  margin: 24px 0;
}

.hero .logo {
  width: 96px;
  height: 96px;
  border-radius: 22px;
}

.hero p {
  color: var(--muted);
}

.center {
  text-align: center;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

.notice,
.error,
.warning {
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 16px;
}

.notice {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.error {
  background: var(--error-bg);
  color: var(--error-text);
}

.warning {
  background: var(--live-bg);
  color: var(--live-text);
}

.warning p {
  margin: 4px 0;
}

.warning a {
  color: inherit;
  font-weight: 600;
}

.back {
  color: var(--muted);
  text-decoration: none;
}

/* --- Formulaires --- */

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 0;
}

input,
select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 400;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}

input:focus,
select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
}

.btn.block {
  display: flex;
  width: 100%;
}

.btn.small {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 0.9rem;
}

.btn.danger-link {
  border-color: transparent;
  background: transparent;
  color: var(--stop);
}

.btn:disabled {
  opacity: 0.6;
}

form.center {
  margin-top: 8px;
}

/* --- Pointage --- */

.greeting {
  font-size: 1.3rem;
}

.clock {
  margin: 0 0 20px;
  text-align: center;
}

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

.clock-label {
  margin: 0;
  color: var(--muted);
}

.clock-elapsed {
  margin: 4px 0 12px;
  font-size: 2.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.btn-clock {
  width: 100%;
  min-height: 96px;
  border: 0;
  border-radius: 24px;
  color: #ffffff;
  font: inherit;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.btn-clock.start {
  background: var(--start);
}

.btn-clock.stop {
  background: var(--stop);
}

.btn-clock:active {
  transform: scale(0.98);
}

/* --- Mois & totaux --- */

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

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
  text-decoration: none;
}

.btn-icon.disabled {
  opacity: 0.3;
}

.total {
  background: var(--primary);
  color: var(--primary-text);
  border-radius: var(--radius);
  padding: 18px;
  margin: 0 0 16px;
  text-align: center;
}

.total-hours {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.1;
}

.total-amount {
  font-size: 1.3rem;
  font-weight: 600;
}

.total-meta {
  margin-top: 6px;
  font-size: 0.9rem;
  opacity: 0.9;
}

.total .badge.ok {
  background: rgba(255, 255, 255, 0.2);
  color: inherit;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.badge.ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.badge.live {
  background: var(--live-bg);
  color: var(--live-text);
}

.badge.muted {
  opacity: 0.7;
}

/* --- Listes --- */

.shifts,
.rows,
.sitters {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.shifts {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.shifts li + li {
  border-top: 1px solid var(--border);
}

.shift {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 2px 12px;
  align-items: baseline;
  padding: 12px 16px;
  color: var(--text);
  text-decoration: none;
}

a.shift:active {
  background: var(--bg);
}

.shift-day {
  font-weight: 600;
  min-width: 5.5em;
}

.shift-hours {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.shift-dur {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.shift-note {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.85rem;
}

.rows li {
  margin: 0 0 10px;
}

.rows a {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.row-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.row-amount {
  font-weight: 700;
  font-size: 1.05rem;
  text-align: end;
}

.row-hours {
  color: var(--muted);
}

.rows .badge {
  justify-self: end;
}

.grand-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  margin: 0 0 16px;
  border-top: 2px solid var(--border);
  font-size: 1.1rem;
}

.sitter-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.inline-form {
  grid-template-columns: 1fr 6.5em;
  align-items: end;
}

.inline-form .btn {
  grid-column: 1 / -1;
}

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

.link-box {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.85rem;
}


.section-title {
  margin: 24px 0 12px;
}

/* --- Raccourcis du formulaire de garde --- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 40px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.chip.wide {
  flex-basis: 100%;
}

.chip[aria-pressed="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
}

.preview {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--ok-bg);
  color: var(--ok-text);
  font-weight: 600;
}

/* --- Choix de la langue (bas de page) --- */

.langs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin: 32px 0 8px;
}

.langs button {
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.langs button[aria-current="true"] {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
}

/* --- Langues écrites de droite à gauche (arabe) --- */

[dir="rtl"] select {
  background-position: 12px 50%, 18px 50%;
}

.card .langs {
  justify-content: flex-start;
  margin: 0;
}

.card .langs button {
  border: 1px solid var(--border);
}

.card .langs button[aria-current="true"] {
  border-color: var(--primary);
}
