:root {
  --green: #1F4D3A;
  --accent: #C08A34;
  --on-primary: #FFFFFF;
  --on-accent: #2A1B06;
  --text: #22261F;
  --muted: #6B6A5C;
  --border: #DDD3BC;
  --bg: #EFE9DC;
  --card-bg: #FBF8F1;
  --red: #D9412B;
  --light-bg: #E4DCC8;
  --warn-bg: #FFF4E5;
  --warn-border: #F3C98B;
  --danger-bg: #FDECEA;
  --danger-border: #F3B4AB;
  --ok-bg: #E4EEDF;
}

:root[data-theme="dark"] {
  --green: #6FBF9B;
  --accent: #D9A85C;
  --on-primary: #0E1C15;
  --on-accent: #241806;
  --text: #EDE9DD;
  --muted: #A6A290;
  --border: #332F24;
  --bg: #14140F;
  --card-bg: #1D2019;
  --red: #FF6B57;
  --light-bg: #211F17;
  --warn-bg: #3A2F14;
  --warn-border: #6B5423;
  --danger-bg: #3A1F1C;
  --danger-border: #6B3A34;
  --ok-bg: #1D3327;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Tajawal", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s, color 0.2s;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }

.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; width: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card-bg); border-bottom: 1px solid var(--border);
}
.topbar-inner { height: 56px; display: flex; align-items: center; justify-content: space-between; }
.brand { font-weight: 800; font-size: 18px; color: var(--green); display: flex; align-items: center; gap: 8px; }
.brand-logo { width: 26px; height: 26px; flex-shrink: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card-bg); font-size: 16px; color: var(--text); flex-shrink: 0;
}
.emergency-btn {
  display: flex; align-items: center; gap: 4px;
  background: var(--accent); color: var(--on-accent); padding: 6px 12px;
  border-radius: 999px; font-weight: 700; font-size: 14px;
}

.page { flex: 1; padding: 16px; padding-bottom: 96px; }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--card-bg); border-top: 1px solid var(--border);
}
.bottom-nav-inner { display: grid; grid-template-columns: repeat(5, 1fr); }
.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 10px 0; color: var(--muted); font-size: 12px; font-weight: 500; gap: 2px;
}
.nav-icon { font-size: 20px; line-height: 1; }

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

.card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 16px; padding: 16px;
}
.card.shadow { box-shadow: 0 1px 3px rgba(0,0,0,.06); padding: 20px; }
.card.center { text-align: center; display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.card-flat { background: var(--light-bg); border-radius: 12px; padding: 12px; color: var(--muted); }

.section-label { font-size: 14px; color: var(--muted); margin: 0 0 8px; }
.title-lg { font-size: 20px; font-weight: 700; margin: 0; }
.title-xl { font-size: 22px; font-weight: 700; margin: 0; }
.muted { color: var(--muted); }
.accent { color: var(--green); font-weight: 700; }
.accent-text { color: var(--green); }
.danger-text { color: var(--red); }
.bold { font-weight: 700; }
.sm { font-size: 14px; }
.xs { font-size: 12px; }
.mb { margin-bottom: 16px; }
.mt { margin-top: 8px; }
.block { display: block; }
.pointer { cursor: pointer; }

.row-between { display: flex; align-items: center; justify-content: space-between; }
.row-start { display: flex; align-items: center; gap: 8px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.row-actions { display: flex; gap: 8px; font-size: 14px; padding-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.field { display: block; }
.field-label { font-size: 14px; font-weight: 700; display: block; margin-bottom: 4px; }
.field-label.sm { font-size: 12px; color: var(--muted); font-weight: 400; }

input, select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; font-family: inherit; font-size: 15px; background: var(--card-bg); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: 1px; }

.btn {
  display: inline-block; text-align: center; border-radius: 12px; font-weight: 700;
  padding: 12px 16px; border: none; font-size: 15px;
}
.btn-primary { background: var(--green); color: var(--on-primary); }
.btn-outline { background: var(--card-bg); border: 1px solid var(--border); color: var(--green); }
.btn-danger-outline { background: var(--card-bg); border: 1px solid var(--border); color: var(--red); }
.btn-sm { padding: 8px 16px; font-size: 14px; border-radius: 12px; }
.btn-lg { width: 100%; padding: 14px; font-size: 17px; border-radius: 12px; }
.flex1 { flex: 1; }

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

.btn-xs { padding: 8px 10px; font-size: 13px; border-radius: 10px; }

/* ─── بطاقات أدوية اليوم — شبكة مضغوطة بدل قائمة طويلة ─── */
.dose-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px;
}
.dose-card {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px;
  background: var(--light-bg); border-radius: 14px; padding: 12px 8px;
}
.dose-card-photo { width: 44px; height: 44px; }
.dose-card-icon {
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  font-size: 22px; background: var(--card-bg); border-radius: 10px; border: 1px solid var(--border);
}
.dose-card-name {
  font-weight: 700; font-size: 13px; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.dose-card-time { color: var(--muted); font-size: 11px; margin: 0; }
.dose-card-actions { display: flex; gap: 4px; margin-top: 2px; }
.dose-card-actions .btn-xs { padding: 7px 8px; }

.link { color: var(--green); font-weight: 700; font-size: 14px; }
.center-link { display: block; text-align: center; color: var(--muted); font-size: 14px; padding: 8px 0; }

.link-btn { background: none; border: none; padding: 0; font-weight: 700; color: var(--muted); font-size: inherit; }

.badge {
  font-size: 12px; background: var(--light-bg); color: var(--muted);
  padding: 4px 10px; border-radius: 999px;
}
.badge-ok { background: var(--ok-bg); color: var(--green); }
.badge-danger { background: var(--danger-bg); color: var(--red); }

/* ─── Auth (تسجيل الدخول/حساب جديد) — بسيط لكبار السن ─── */
.auth-wrap {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 24px 16px; gap: 20px;
}
.auth-brand {
  font-weight: 800; font-size: 22px; color: var(--green); margin: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.auth-lang-switch { display: flex; gap: 8px; margin-bottom: 4px; }
.lang-pill {
  border: 1px solid var(--border); background: var(--card-bg); color: var(--muted);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 700;
}
.lang-pill-active { background: var(--green); color: var(--on-primary); border-color: var(--green); }
.auth-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 20px;
  padding: 28px 24px; width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 18px;
}
.auth-title { font-size: 22px; font-weight: 800; text-align: center; margin: 0; }
.auth-error {
  background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--red);
  border-radius: 12px; padding: 10px 14px; font-size: 14px; text-align: center; margin: 0;
}
.auth-input {
  width: 100%; border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; font-size: 20px; text-align: center; font-family: inherit;
}
.auth-pin { letter-spacing: 12px; }
.auth-user-list { display: flex; flex-direction: column; gap: 10px; }
.auth-user-btn {
  display: block; text-align: center; background: var(--light-bg); border-radius: 14px;
  padding: 16px; font-size: 18px; font-weight: 700; color: var(--text);
}
.auth-link { display: block; text-align: center; color: var(--muted); font-size: 14px; }

.invite-code {
  font-size: 32px; font-weight: 800; letter-spacing: 6px; color: var(--green); margin: 4px 0 0;
}

/* ─── صورة الدواء ─── */
.photo-pick-btn { position: relative; display: block; cursor: pointer; }
.photo-file-input {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer;
}
.photo-preview {
  width: 100%; max-height: 220px; object-fit: cover; border-radius: 14px;
  border: 1px solid var(--border);
}
.med-thumb {
  width: 48px; height: 48px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--border); flex-shrink: 0; cursor: pointer;
}
.photo-lightbox[hidden] { display: none; }
.photo-lightbox {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.photo-lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }

.switch-check { width: 26px; height: 26px; accent-color: var(--green); }

.duration-grid { margin-top: 6px; gap: 8px; }
.duration-btn { font-size: 14px; padding: 12px 8px; }
.duration-btn-active { background: var(--green); color: var(--on-primary); border-color: var(--green); }

/* ─── شاشة الترحيب (Splash) ─── */
.splash {
  position: fixed; inset: 0; z-index: 100; background: var(--card-bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center;
  opacity: 1; transition: opacity 0.5s ease;
}
.splash-hide { opacity: 0; pointer-events: none; }
.splash-logo { width: 140px; height: 140px; object-fit: contain; border-radius: 20px; }
.splash-dedication { font-size: 20px; font-weight: 800; color: var(--text); margin: 0; }
.splash-role { font-size: 15px; color: var(--muted); margin: 0; }
.splash-free { font-size: 15px; font-weight: 700; color: var(--green); margin-top: 8px; }
.splash-instagram { font-size: 13px; color: var(--muted); text-decoration: underline; }
.splash .btn { margin-top: 12px; min-width: 140px; }

/* ─── الماء ─── */
.water-total { font-size: 36px; font-weight: 800; color: var(--green); margin: 0; }
.progress-bar {
  width: 100%; height: 14px; background: var(--light-bg); border-radius: 999px;
  overflow: hidden; margin-top: 10px;
}
.progress-fill { height: 100%; background: var(--green); border-radius: 999px; transition: width 0.3s; }

/* ─── بطاقة الطوارئ ─── */
.emergency-disclaimer {
  background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 12px;
  padding: 12px 14px; font-size: 13px; color: var(--text);
}
