:root {
  --primary: #3d5a3a;
  --primary-dark: #283d26;
  --primary-light: #eaf0e6;
  --accent: #c8a24d;
  --accent-dark: #a9853a;
  --danger: #c0392b;
  --text: #23312d;
  --muted: #6b7d78;
  --bg: #c7cbce;
  --card: #ffffff;
  --border: #dde8e3;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(30, 45, 25, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Tahoma", "Cairo", sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  text-align: right;
}

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }
.container-narrow { max-width: 560px; margin: 0 auto; padding: 24px 16px; }

/* Topbar */
.topbar {
  background: var(--primary);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.topbar .brand { font-weight: 700; font-size: 1.15rem; display:flex; align-items:center; gap:10px; }
.topbar .brand img { height: 32px; width: auto; display: block; }
.topbar nav { display: flex; gap: 10px; align-items: center; }
.topbar a, .topbar button.link {
  color: #fff; text-decoration: none; font-size: .92rem; opacity: .92;
  background: none; border: none; cursor: pointer; font-family: inherit;
}
.topbar a:hover, .topbar button.link:hover { opacity: 1; text-decoration: underline; }
.topbar .user-chip {
  background: rgba(255,255,255,.15); padding: 4px 14px; border-radius: 20px; font-size: .85rem;
  display: flex; align-items: center; gap: 8px;
}
.chip-avatar {
  width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
}
.chip-avatar-placeholder {
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.35); color: #fff; font-weight: 700; font-size: .8rem;
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card h2 { margin-top: 0; font-size: 1.1rem; color: var(--primary-dark); }
.card h3 {
  font-size: .95rem; color: var(--primary-dark); border-bottom: 2px solid var(--primary-light);
  padding-bottom: 6px; margin: 0 0 14px;
}
.section-icon { margin-left: 6px; }

/* Grid form layout */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.field input[type=text], .field input[type=number], .field input[type=email],
.field input[type=password], .field input[type=date], .field select, .field textarea {
  padding: 9px 12px; border: 2px solid #1a1a1a; border-radius: 8px;
  font-size: .92rem; font-family: inherit; background: #fff; color: var(--text);
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
}
.field input:disabled, .field select:disabled, .field textarea:disabled {
  background: #eee; color: var(--muted); border-color: var(--border); cursor: not-allowed;
}

/* Checkbox groups */
.check-group { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.check-item { display: flex; align-items: center; gap: 6px; font-size: .9rem; }
.check-item input { accent-color: var(--primary); }

.radio-row { display: flex; flex-wrap: wrap; gap: 14px; }
.radio-item { display: flex; align-items: center; gap: 6px; font-size: .9rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: none; border-radius: 8px;
  padding: 10px 20px; font-size: .92rem; cursor: pointer; font-family: inherit;
  transition: background .15s;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn.secondary:hover { background: var(--primary-light); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #96271d; }
.btn.success { background: #1c7a3d; }
.btn.success:hover { background: #145c2d; }
.btn.small { padding: 6px 12px; font-size: .82rem; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 700; background: var(--primary-light); }
tr:hover td { background: #fafdfc; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.badge.green { background: #e2f5e9; color: #1c7a3d; }
.badge.orange { background: #fdecd8; color: #b9631a; }
.badge.red { background: #fbe4e1; color: var(--danger); }
.badge.gray { background: #eee; color: var(--muted); }
.badge.blue { background: #e0edfb; color: #1a5fa8; }

/* Auth page */
.auth-tabs { display: flex; gap: 6px; margin-bottom: 20px; background: #eef4f1; border-radius: 10px; padding: 4px; }
.auth-tabs button {
  flex: 1; padding: 10px; border: none; background: transparent; border-radius: 8px;
  cursor: pointer; font-family: inherit; font-size: .92rem; color: var(--muted);
}
.auth-tabs button.active { background: var(--primary); color: #fff; }
.logo-block { text-align: center; margin-bottom: 22px; }
.logo-block .emoji { font-size: 2.4rem; }
.logo-block h1 { margin: 6px 0 2px; color: var(--primary-dark); font-size: 1.4rem; }
.logo-block p { color: var(--muted); margin: 0; font-size: .9rem; }

.role-toggle { display: flex; gap: 10px; margin-bottom: 8px; }
.role-toggle label {
  flex: 1; text-align: center; padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; font-size: .88rem;
}
.role-toggle input { display: none; }
.role-toggle input:checked + span { color: var(--primary); font-weight: 700; }
.role-toggle label:has(input:checked) { border-color: var(--primary); background: var(--primary-light); }

.msg { padding: 10px 14px; border-radius: 8px; font-size: .88rem; margin-bottom: 14px; }
.msg.error { background: #fbe4e1; color: var(--danger); }
.msg.success { background: #e2f5e9; color: #1c7a3d; }

/* Stat cards */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--shadow); }
.stat-card .value { font-size: 1.6rem; font-weight: 800; color: var(--primary-dark); }
.stat-card .label { font-size: .82rem; color: var(--muted); margin-top: 4px; }

.search-row { display: flex; gap: 10px; margin-bottom: 16px; }
.search-row input { flex: 1; padding: 10px 14px; border: 2px solid #1a1a1a; border-radius: 8px; font-family: inherit; }

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

.tabs-nav { display: flex; gap: 8px; border-bottom: 2px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; padding-bottom: 10px; }
.tabs-nav a {
  padding: 9px 18px; text-decoration: none; color: var(--muted); font-size: .9rem;
  border-radius: 20px; transition: background .15s, color .15s;
}
.tabs-nav a:hover { background: var(--primary-light); color: var(--primary-dark); }
.tabs-nav a.active {
  background: var(--primary); color: #fff; font-weight: 700;
  box-shadow: var(--shadow);
}
.tabs-nav a.active:hover { background: var(--primary); color: #fff; }

.note-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.note-item:last-child { border-bottom: none; }
.note-item .meta { font-size: .78rem; color: var(--muted); margin-bottom: 4px; }

footer.hint { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 14px; }
a.plain { color: var(--primary); }

/* Modal (confirmation dialogs — e.g. "Confirm & Send WhatsApp") */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 30, 20, .55);
  display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px;
}
.modal-box {
  background: var(--card); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.25);
  padding: 24px; max-width: 480px; width: 100%; max-height: 90vh; overflow-y: auto;
}
.modal-box h3 { margin-top: 0; color: var(--primary-dark); }
.modal-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.modal-row:last-of-type { border-bottom: none; }
.modal-row .k { color: var(--muted); }
.modal-row .v { font-weight: 700; text-align: left; }

/* Message preview box (WhatsApp-style, monospace-ish, preserves line breaks) */
.wa-preview {
  background: #e9f7ef; border: 1px solid #cfead9; border-radius: 10px; padding: 16px;
  white-space: pre-wrap; font-size: .92rem; line-height: 1.7; color: var(--text);
}

.char-counter { font-size: .76rem; color: var(--muted); text-align: left; margin-top: 2px; }
.char-counter.over { color: var(--danger); font-weight: 700; }

/* Nutrition plan — day tabs (patient-facing) */
.day-tabs-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.day-tab-btn {
  padding: 8px 20px; border-radius: 20px; border: 1px solid var(--border); background: #fff;
  color: var(--muted); cursor: pointer; font-family: inherit; font-size: .88rem;
  transition: background .15s, color .15s, border-color .15s;
}
.day-tab-btn:hover { background: var(--primary-light); color: var(--primary-dark); }
.day-tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 700; box-shadow: var(--shadow); }

/* Nutrition plan — day tabs that deviate beyond the calorie tolerance
   (doctor-facing: AI preview + saved plan builder, both use .btn small) */
.btn.day-tab-warn { border: 2px solid #b9631a; color: #b9631a; }
.btn.day-tab-warn.secondary { background: #fdecd8; }
.btn.day-tab-warn:not(.secondary) { background: #b9631a; border-color: #b9631a; color: #fff; }

/* Nutrition plan — meal cards (patient-facing) */
.meal-block {
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  margin-bottom: 18px; box-shadow: var(--shadow);
}
.meal-block:last-child { margin-bottom: 0; }
.meal-block-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--primary-light); padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.meal-block-header .meal-title { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--primary-dark); font-size: 1rem; }
.meal-block-header .meal-icon { font-size: 1.15rem; }
.meal-block-header .meal-time { font-size: .8rem; color: var(--muted); font-weight: 400; }
.meal-block-header .meal-total { flex-shrink: 0; }
.meal-block table { margin: 0; border-collapse: collapse; }
.meal-block th, .meal-block td {
  border: 1px solid var(--border);
  padding: 14px 16px;
}
.meal-block th {
  background: var(--primary-light); font-size: 1rem; font-weight: 800; color: var(--primary-dark);
  border-color: #c7d9c3;
}
.meal-block td { font-size: .98rem; line-height: 1.5; }
.meal-block td:first-child { font-weight: 700; color: var(--text); }
.meal-block tbody tr:nth-child(odd) td { background: #ffffff; }
.meal-block tbody tr:nth-child(even) td { background: #f2f7f3; }
.meal-block tbody tr:hover td { background: var(--primary-light); }
.meal-block .col-alt, .meal-block .col-note { color: var(--muted); font-size: .92rem; }

.day-section-title {
  display: flex; align-items: center; gap: 10px; margin: 26px 0 14px; font-size: 1.05rem;
  color: var(--primary-dark); font-weight: 800;
}
.day-section-title:first-child { margin-top: 0; }
.day-section-title .day-badge {
  background: var(--primary); color: #fff; border-radius: 8px; padding: 3px 12px; font-size: .85rem;
}
.day-section-title .day-cal { color: var(--muted); font-size: .82rem; font-weight: 400; }

.plan-day-hidden { display: none; }

@media print {
  .day-tabs-row { display: none !important; }
  .plan-day-hidden { display: block !important; }
  .meal-block { box-shadow: none; break-inside: avoid; }
}
