:root {
  --green: #0e7c66;
  --green-light: #e4f5f0;
  --orange: #b26a00;
  --orange-light: #fff2df;
  --red: #b3261e;
  --red-light: #fce8e6;
  --bg: #f4f6f5;
  --card-bg: #ffffff;
  --text: #1c2321;
  --text-muted: #6b7570;
  --border: #e4e8e6;
  --radius: 16px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  padding-top: calc(16px + env(safe-area-inset-top));
  background: var(--green);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand-badge {
  font-weight: 800;
  font-size: 1.4rem;
  letter-spacing: 0.5px;
}

.brand-sub {
  font-size: 0.8rem;
  opacity: 0.9;
}

.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid var(--border);
}

.card-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 700;
}

.muted {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.85rem;
}

/* STATUS CARD */
.status-card {
  display: flex;
  align-items: center;
  gap: 14px;
  transition: background 0.3s;
}

.status-card.status-ok { background: var(--green-light); border-color: var(--green); }
.status-card.status-wait { background: var(--orange-light); border-color: var(--orange); }
.status-card.status-danger { background: var(--red-light); border-color: var(--red); }

.status-icon { font-size: 2rem; line-height: 1; }

.status-text { flex: 1; min-width: 0; }

.status-title { font-weight: 700; font-size: 1.05rem; }
.status-ok .status-title { color: var(--green); }
.status-wait .status-title { color: var(--orange); }
.status-danger .status-title { color: var(--red); }

.status-sub { font-size: 0.85rem; color: var(--text-muted); margin-top: 2px; }

.countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.3rem;
  white-space: nowrap;
}
.status-ok .countdown { color: var(--green); }
.status-wait .countdown { color: var(--orange); }
.status-danger .countdown { color: var(--red); }

/* TAKE BUTTON */
.take-card { text-align: center; }

.take-btn {
  width: 100%;
  padding: 18px;
  border: none;
  border-radius: 14px;
  background: var(--green);
  color: white;
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}
.take-btn:active { transform: scale(0.97); }
.take-btn.small { padding: 12px 18px; font-size: 0.95rem; width: auto; }

.take-btn-icon { font-size: 1.3rem; }

.take-hint {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* SCHEDULES */
.schedules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.schedule-box {
  border-radius: 12px;
  padding: 14px 12px;
  text-align: center;
}
.schedule-box.urgence { background: var(--red-light); }
.schedule-box.confort { background: var(--green-light); }

.schedule-label {
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.65rem;
  background: rgba(0,0,0,0.08);
  padding: 1px 6px;
  border-radius: 20px;
  font-weight: 600;
}

.schedule-time {
  font-size: 1.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.schedule-note {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* DOSE SUMMARY */
.dose-summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.dose-numbers {
  font-size: 1.6rem;
  font-weight: 800;
}

.dose-max {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 500;
}

.dose-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.progress-bar {
  height: 10px;
  background: var(--border);
  border-radius: 20px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 20px;
  transition: width 0.3s, background 0.3s;
}

.dose-remaining {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* HISTORY */
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-list .empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 8px 0;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
}

.history-item-main {
  display: flex;
  flex-direction: column;
}

.history-time {
  font-weight: 700;
  font-size: 0.95rem;
}

.history-date {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.history-delete {
  background: none;
  border: none;
  color: var(--red);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 6px;
}

.text-btn {
  background: none;
  border: none;
  color: var(--green);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px;
}
.text-btn.danger { color: var(--red); }
.text-btn.full { width: 100%; text-align: center; margin-top: 8px; }

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

.topbar-actions a.icon-btn {
  text-decoration: none;
}

.error-banner {
  background: var(--red-light);
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
}

.app-footer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 10px 20px 30px;
  line-height: 1.4;
}

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}

.modal-panel {
  position: relative;
  background: var(--card-bg);
  width: 100%;
  max-width: 560px;
  border-radius: 20px 20px 0 0;
  padding: 20px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease-out;
}

.modal-panel.small {
  border-radius: 20px;
  align-self: center;
  margin: auto;
}

@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-panel { border-radius: 20px; }
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row.column { flex-direction: column; align-items: stretch; }

.setting-label { font-weight: 600; font-size: 0.92rem; }
.setting-desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

.setting-row input[type="checkbox"] {
  width: 44px;
  height: 26px;
  flex-shrink: 0;
  accent-color: var(--green);
}

#confortInterval {
  margin-top: 10px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
  background: var(--bg);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a;
    --card-bg: #1e2426;
    --text: #eef1f0;
    --text-muted: #98a3a0;
    --border: #2b3234;
    --green-light: #123c33;
    --orange-light: #3a2c12;
    --red-light: #3a1a17;
  }
}

/* LOGIN */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 26px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.login-badge {
  display: inline-block;
  background: var(--green);
  color: white;
  font-weight: 800;
  font-size: 1.2rem;
  padding: 8px 18px;
  border-radius: 10px;
  margin-bottom: 16px;
}

.login-card h1 {
  font-size: 1.2rem;
  margin: 0 0 8px;
}

.login-sub {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 0 0 22px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-form input {
  width: 100%;
  padding: 14px;
  font-size: 1.3rem;
  text-align: center;
  letter-spacing: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.login-error {
  color: var(--red);
  font-size: 0.85rem;
  font-weight: 600;
}
