:root {
  --bg-from: #0f5b73;
  --bg-to: #1581a3;
  --panel: #093442;          /* buttons & cards */
  --panel-2: #0c4356;        /* slightly lighter panel for nesting */
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.72);
  --faint: rgba(255, 255, 255, 0.14);
  --line: rgba(255, 255, 255, 0.16);
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg-from), var(--bg-to));
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
}

a { color: #bde7f5; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 700; line-height: 1.2; }
h1 { font-size: 1.7rem; margin: 0 0 .25rem; }
p { color: var(--muted); line-height: 1.55; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .9rem 1.5rem;
  background: rgba(9, 52, 66, 0.55);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 1.5rem; }
.brand-text { font-size: 1.2rem; font-weight: 600; letter-spacing: .3px; }
.brand-text strong { font-weight: 800; }
.nav { display: flex; gap: .35rem; flex: 1; flex-wrap: wrap; }
.nav a {
  color: var(--muted); padding: .45rem .8rem; border-radius: 10px;
  font-weight: 500; font-size: .92rem;
}
.nav a:hover { color: #fff; background: var(--faint); text-decoration: none; }
.nav a.active { color: #fff; background: var(--panel); }
.ai-badge {
  display: flex; align-items: center; gap: .4rem;
  font-size: .8rem; font-weight: 600; padding: .35rem .7rem;
  border-radius: 999px; border: 1px solid var(--line);
}
.ai-badge .dot { width: 8px; height: 8px; border-radius: 50%; }
.ai-badge.on .dot { background: var(--good); box-shadow: 0 0 8px var(--good); }
.ai-badge.off .dot { background: var(--bad); }

/* ---------- layout ---------- */
.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 1.75rem 1.25rem 3rem; flex: 1; }
.grid { display: grid; gap: 1.1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

/* ---------- cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1.15rem; margin: 0 0 .9rem; }
.card h3 { font-size: 1rem; margin: 1rem 0 .5rem; color: #d6f0fa; }
.card.tight { padding: 1rem 1.1rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }

/* stat cards */
.stat { text-align: center; }
.stat .value { font-size: 1.9rem; font-weight: 800; }
.stat .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat .sub { font-size: .8rem; color: var(--muted); margin-top: .15rem; }

/* ---------- forms ---------- */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin: 0 0 .35rem; }
input, select, textarea {
  width: 100%; padding: .6rem .75rem; font: inherit; color: #fff;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; outline: none;
}
input::placeholder, textarea::placeholder { color: rgba(255,255,255,.4); }
input:focus, select:focus, textarea:focus { border-color: #58c6e8; box-shadow: 0 0 0 3px rgba(88,198,232,.18); }
select option { color: #093442; }
textarea { resize: vertical; min-height: 80px; }
.field { margin-bottom: 1rem; }
.row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  background: var(--panel); color: #fff; border: 1px solid var(--line);
  padding: .7rem 1.25rem; border-radius: 12px; font-weight: 600; font-size: .95rem;
  cursor: pointer; transition: transform .08s ease, background .15s ease;
}
.btn:hover { background: var(--panel-2); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: linear-gradient(135deg, #0c4356, #093442); border-color: #2c7e9c; }
.btn.full { width: 100%; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- chips / badges ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  background: var(--panel-2); border: 1px solid var(--line);
  padding: .3rem .7rem; border-radius: 999px; font-size: .82rem; color: #e6f6fc;
}
.chip.good { border-color: var(--good); color: #c6f6d5; }
.chip.bad  { border-color: var(--bad);  color: #fed7d7; }

.pill { display:inline-block; padding:.2rem .6rem; border-radius:999px; font-size:.75rem; font-weight:700; text-transform:uppercase; letter-spacing:.4px; }
.pill.low { background: rgba(74,222,128,.18); color: var(--good); }
.pill.moderate { background: rgba(251,191,36,.18); color: var(--warn); }
.pill.high { background: rgba(248,113,113,.18); color: var(--bad); }

/* ---------- score ring ---------- */
.score-ring { --val: 0; width: 120px; height: 120px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--ring) calc(var(--val)*1%), var(--faint) 0); position: relative; }
.score-ring::before { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--panel); }
.score-ring .num { position: relative; font-size: 1.8rem; font-weight: 800; }
.score-ring .num small { font-size: .8rem; font-weight: 500; color: var(--muted); }

/* ---------- lists ---------- */
ul.clean { list-style: none; padding: 0; margin: .3rem 0; }
ul.clean li { padding: .4rem 0; border-bottom: 1px solid var(--faint); color: #eaf7fc; }
ul.clean li:last-child { border-bottom: none; }
ul.bullets { padding-left: 1.1rem; margin: .3rem 0; }
ul.bullets li { padding: .2rem 0; color: #eaf7fc; }

/* meal plan table */
.plan { width: 100%; border-collapse: collapse; font-size: .9rem; }
.plan th, .plan td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--faint); }
.plan th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; }

/* flash */
.flash { padding: .8rem 1rem; border-radius: 12px; margin-bottom: 1rem; border: 1px solid var(--line); background: var(--panel); }
.flash.success { border-color: var(--good); }
.flash.error { border-color: var(--bad); }
.flash.info { border-color: #58c6e8; }

/* thumbnails */
.thumb { width: 100%; max-height: 260px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.thumb-sm { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }

.muted { color: var(--muted); }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.foot { text-align: center; padding: 1.5rem; font-size: .82rem; color: var(--muted); border-top: 1px solid var(--line); }

/* ---------- user menu ---------- */
.user-menu { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.user-menu .who { font-size: .85rem; color: var(--muted); }
.tag { background: var(--good); color: #06303a; font-size: .65rem; font-weight: 800; padding: .1rem .4rem; border-radius: 999px; text-transform: uppercase; }
.btn-sm { padding: .4rem .8rem; font-size: .85rem; border-radius: 10px; }

/* ---------- language switcher ---------- */
.lang-switch { display: flex; align-items: center; gap: .3rem; font-size: .82rem; }
.lang-switch a { color: var(--muted); padding: .15rem .35rem; border-radius: 6px; }
.lang-switch a:hover { color: #fff; background: var(--faint); text-decoration: none; }
.lang-switch a.on { color: #fff; background: var(--panel); font-weight: 600; }

/* ---------- RTL (Arabic) ---------- */
[dir="rtl"] body, [dir="rtl"] { text-align: right; }
[dir="rtl"] .nav, [dir="rtl"] .user-menu, [dir="rtl"] .section-head,
[dir="rtl"] .chat-input, [dir="rtl"] .actions, [dir="rtl"] .suggest { direction: rtl; }
[dir="rtl"] .plan th, [dir="rtl"] .plan td,
[dir="rtl"] .admin-table th, [dir="rtl"] .admin-table td { text-align: right; }
[dir="rtl"] ul.bullets { padding-left: 0; padding-right: 1.1rem; }
[dir="rtl"] .bubble.user { align-self: flex-start; }
[dir="rtl"] .bubble.assistant { align-self: flex-end; }

/* ---------- auth pages ---------- */
.auth-wrap { max-width: 420px; margin: 3rem auto 0; }
.auth-wrap .card { padding: 1.75rem; }
.auth-wrap h1 { text-align: center; }
.auth-sub { text-align: center; margin-bottom: 1.5rem; }
.auth-alt { text-align: center; margin-top: 1.25rem; font-size: .9rem; }

/* ---------- admin table ---------- */
.admin-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.admin-table th, .admin-table td { padding: .6rem .55rem; border-bottom: 1px solid var(--faint); text-align: left; vertical-align: middle; }
.admin-table th { color: var(--muted); font-size: .75rem; text-transform: uppercase; }
.status { font-size: .72rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; text-transform: uppercase; }
.status.active { background: rgba(74,222,128,.18); color: var(--good); }
.status.pending { background: rgba(251,191,36,.18); color: var(--warn); }
.status.suspended { background: rgba(248,113,113,.18); color: var(--bad); }
.actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.actions form { display: inline; }
.icon-btn { background: var(--panel-2); border: 1px solid var(--line); color: #fff; cursor: pointer;
  padding: .3rem .55rem; border-radius: 8px; font-size: .78rem; }
.icon-btn:hover { background: #114a5e; }
.icon-btn.danger:hover { background: #5a1f1f; border-color: var(--bad); }
.scroll-x { overflow-x: auto; }

/* ---------- chat ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 230px); min-height: 420px; }
.chat-log { flex: 1; overflow-y: auto; padding: .5rem; display: flex; flex-direction: column; gap: .75rem; }
.bubble { max-width: 80%; padding: .7rem .95rem; border-radius: 14px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.bubble.user { align-self: flex-end; background: var(--panel-2); border: 1px solid #2c7e9c; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.assistant strong { color: #d6f0fa; }
.chat-input { display: flex; gap: .6rem; margin-top: .75rem; }
.chat-input textarea { flex: 1; min-height: 48px; max-height: 140px; }
.suggest { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.suggest button { background: var(--panel-2); border: 1px solid var(--line); color: #e6f6fc; padding: .45rem .8rem; border-radius: 999px; font: inherit; font-size: .85rem; cursor: pointer; }
.suggest button:hover { background: #114a5e; }
.typing { align-self: flex-start; color: var(--muted); font-size: .9rem; padding: .4rem .6rem; }

@media (max-width: 640px) {
  .topbar { gap: .75rem; }
  .nav { order: 3; width: 100%; }
}
