/* Afyvia design system: one set of colours, type and components for the website, the sign-in page, the web app and the
   admin dashboard. Light is the default; dark is an option the visitor chooses (theme.js sets data-theme on <html>). */

:root {
  color-scheme: light;
  /* brand: the logo's petrol blue and turquoise */
  --primary: #075f7c;
  --primary-dark: #084a65;
  --primary-soft: #e3f1f7;
  --accent: #087463;
  --brand-name: var(--primary);
  --accent-soft: #e1f4ee;
  --on-accent: #ffffff;
  --on-primary: #ffffff;
  --band-start: #103e5d;
  --band-end: #075c51;
  --band-text: #ffffff;
  --band-muted: #dbeeea;
  --band-accent: #a9f2da;
  --band-tint: #ffffff18;
  --band-track: #ffffff3d;
  --band-ink: #103e5d;
  /* surfaces and text */
  --bg: #f5f8fa;
  --bg-alt: #ffffff;
  --card: #ffffff;
  --surface-2: #edf3f6;
  --ink: #112c3e;
  --muted: #485e6e;
  --line: #dce6ec;
  --line-strong: #c0d1db;
  --control-line: #778d9e;
  /* status colours (always with a text label too) */
  --danger: #a5293c;
  --danger-soft: #fdeeee;
  --on-danger: #ffffff;
  --warn: #795000;
  --warn-soft: #fff2d6;
  --ok: #116548;
  --ok-soft: #e2f3e9;
  --blue: #235c99;
  --blue-soft: #e5f0fb;
  --purple: #5b459f;
  --purple-soft: #eeeafb;
  /* shape and depth */
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(20, 40, 58, .06);
  --shadow: 0 4px 16px rgba(20, 40, 58, .07);
  --shadow-lg: 0 18px 48px rgba(20, 40, 58, .14);
  --ring: 0 0 0 3px color-mix(in srgb, var(--primary) 24%, transparent);
  /* type */
  --font: "DM Sans", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-ar: "IBM Plex Sans Arabic", "DM Sans", system-ui, "Segoe UI", Tahoma, sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --primary: #76d0e6;
  --primary-dark: #a4e3f1;
  --primary-soft: #15384a;
  --accent: #74ddc3;
  --brand-name: #ffffff;
  --accent-soft: #153c38;
  --on-accent: #092b25;
  --on-primary: #092431;
  --band-start: #153d55;
  --band-end: #124d43;
  --bg: #0c1822;
  --bg-alt: #101f2c;
  --card: #142635;
  --surface-2: #1a3040;
  --ink: #ebf3f7;
  --muted: #b0c1cd;
  --line: #2b4457;
  --line-strong: #426074;
  --control-line: #7190a4;
  --danger: #ffabb4;
  --danger-soft: #3a2024;
  --on-danger: #351219;
  --warn: #f2cd80;
  --warn-soft: #3a2f16;
  --ok: #81dfb4;
  --ok-soft: #123a2c;
  --blue: #9cc9fb;
  --blue-soft: #16314d;
  --purple: #c9b9fa;
  --purple-soft: #2a2450;
  --shadow-sm: none;
  --shadow: 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .45);
}

html { font-family: var(--font); color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; text-rendering: optimizeLegibility; }
html[dir="rtl"] { font-family: var(--font-ar); }
body { background: var(--bg); color: var(--ink); }
::selection { background: var(--primary); color: var(--on-primary); }

/* ---- shared interaction details ---- */
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
a { color: var(--primary-dark); text-underline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; } }

/* ---- theme toggle (works in every header) ---- */
.theme-toggle { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--card); color: var(--ink); cursor: pointer; transition: background .2s var(--ease), border-color .2s var(--ease), transform .2s var(--ease); }
.theme-toggle:hover { background: var(--primary-soft); border-color: var(--primary); }
.theme-toggle:active { transform: scale(.94); }
.theme-toggle svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }

/* ---- Afyvia logo and name ---- */
.afyvia-brand {
  --brand-size: 48px;
  display: inline-flex;
  align-items: center;
  gap: .31em;
  max-width: 100%;
  direction: ltr;
  white-space: nowrap;
  font: 800 calc(var(--brand-size) * .6)/1 "DM Sans", system-ui, sans-serif;
  letter-spacing: -.035em;
}
.afyvia-brand img { display: block; width: var(--brand-size); height: var(--brand-size); object-fit: contain; flex: none; }
.afyvia-name {
  color: var(--brand-name);
  unicode-bidi: isolate;
}

.exercise-cover {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 10px;
  color: var(--primary-dark);
  background: linear-gradient(135deg, var(--primary-soft), var(--accent-soft));
}
.exercise-cover.compact { width: 56px; aspect-ratio: 1; flex: none; }
.exercise-cover-placeholder { width: 28px; height: 28px; }
.exercise-cover.compact .exercise-cover-placeholder { width: 22px; height: 22px; }
.exercise-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--primary-soft); }
.exercise-cover-play {
  position: absolute;
  inset-inline-end: 10px;
  inset-block-end: 10px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgb(8 30 47 / .85);
  color: white;
}
.exercise-cover-play svg { width: 20px; height: 20px; }

social-footer:not([hidden]) { display: flex; flex-wrap: wrap; gap: 8px; grid-column: 1 / -1; }
social-footer a { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--primary-dark); background: var(--card); }
social-footer a:hover { border-color: var(--primary); background: var(--primary-soft); }
social-footer svg { width: 20px; height: 20px; }

/* ============================================================ web app (doctor and patient) */
.btn { gap: 8px; min-height: 42px; padding: 0 18px; border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--primary); color: var(--on-primary); font-weight: 600; font-size: 14.5px; box-shadow: none; transition: background .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease), transform .12s var(--ease), box-shadow .18s var(--ease); }
.btn:hover { background: var(--primary-dark); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: wait; transform: none; }
.btn.secondary { background: var(--primary-soft); color: var(--primary-dark); }
.btn.secondary:hover { background: color-mix(in srgb, var(--primary) 18%, var(--card)); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary-dark); }
.btn.danger { background: var(--danger); color: var(--on-danger); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 90%, var(--on-danger)); }
.btn.ghost.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn.ghost.danger:hover { background: var(--danger-soft); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn .ico { width: 18px; height: 18px; }
.icon-btn { width: 40px; height: 40px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--card); color: var(--ink); transition: background .18s var(--ease), border-color .18s var(--ease); }
.icon-btn:hover { background: var(--primary-soft); border-color: var(--primary); }

input, select, textarea { border: 1px solid var(--control-line); border-radius: var(--radius-sm); background: var(--card); color: var(--ink); padding: 10px 13px; min-height: 42px; transition: border-color .18s var(--ease), box-shadow .18s var(--ease); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: var(--primary); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); }
label { color: var(--ink); font-weight: 600; font-size: 13.5px; }
label small, small.muted { color: var(--muted); }
input[type="checkbox"] { accent-color: var(--primary); width: 17px; height: 17px; }
input[type="file"] { padding: 7px; background: var(--surface-2); }
input[type="file"]::file-selector-button { margin-inline-end: 10px; padding: 6px 12px; border: 0; border-radius: 8px; background: var(--primary-soft); color: var(--primary-dark); font: inherit; font-weight: 600; cursor: pointer; }

h1, h2, h3 { color: var(--ink); letter-spacing: -.015em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 17.5px; font-weight: 650; }
.muted { color: var(--muted); }
.page-head { margin-bottom: 22px; }
.page-head h1 { font-size: 26px; }
.page-head p { color: var(--muted); font-size: 14.5px; }

.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow-sm); padding: 20px; transition: box-shadow .2s var(--ease), border-color .2s var(--ease); }
.stat { border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 16px 18px; gap: 4px; }
.stat span { font-size: 13px; font-weight: 500; }
.stat strong { font-size: 26px; font-weight: 700; letter-spacing: -.02em; color: var(--ink); }
.stat.good strong { color: var(--ok); }
.stat.bad strong { color: var(--danger); }
.item { border-bottom-color: var(--line); transition: background .15s var(--ease); }
a.item:hover { background: var(--surface-2); }
.pill { border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.avatar { background: var(--primary-soft); color: var(--primary-dark); font-weight: 650; }
.tabs { background: var(--surface-2); border-radius: 12px; padding: 4px; }
.tab { color: var(--muted); font-weight: 600; border-radius: 9px; transition: background .18s var(--ease), color .18s var(--ease), box-shadow .18s var(--ease); }
.tab:hover { color: var(--ink); }
.tab.active { background: var(--card); color: var(--primary-dark); box-shadow: var(--shadow-sm); }
.chip { border-color: var(--line-strong); color: var(--ink); transition: background .15s var(--ease), border-color .15s var(--ease); }
.chip:hover { border-color: var(--primary); background: var(--primary-soft); }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.note { background: var(--primary-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--primary) 18%, transparent); border-radius: var(--radius-sm); }
.progress { background: var(--surface-2); }
.progress i, .ring-fg { stroke: var(--primary); background: var(--primary); }
.ring-bg { stroke: var(--line); }
.bar i, .line path { background: var(--primary); }
.msg { background: var(--surface-2); }
.msg.me { background: var(--primary); color: var(--on-primary); }

.side { background: var(--card); border-inline-end: 1px solid var(--line); }
.side nav a, .tabbar a { color: var(--muted); font-weight: 600; font-size: 14.5px; transition: background .15s var(--ease), color .15s var(--ease); }
.side nav a:hover { background: var(--surface-2); color: var(--ink); }
.side nav a.active, .tabbar a.active { background: var(--primary-soft); color: var(--primary-dark); }
.top { background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.tabbar { background: var(--card); border-top: 1px solid var(--line); }
main { animation: pageIn .35s var(--ease) both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* feedback: empty, loading, toast, dialog */
.empty { color: var(--muted); padding: 40px 16px; }
.empty .ico { width: 44px; height: 44px; padding: 10px; border-radius: 14px; background: var(--primary-soft); color: var(--primary); }
.empty p { margin: 0; font-size: 14.5px; max-width: 360px; }
.empty.err { color: var(--danger); }
.empty.err .ico { background: var(--danger-soft); color: var(--danger); }
.loading span { background: var(--primary); }
dialog { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); animation: dialogIn .22s var(--ease) both; }
dialog::backdrop { background: rgba(10, 23, 34, .45); backdrop-filter: blur(3px); }
@keyframes dialogIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
table { border-radius: var(--radius-sm); }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; letter-spacing: .02em; }

/* ============================================================ admin dashboard */
button { font-family: inherit; }
body.admin-body, .dashboard { color: var(--ink); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.sidebar { background: var(--card); border-inline-end: 1px solid var(--line); }
.nav-button { color: var(--muted); border-radius: var(--radius-sm); transition: background .15s var(--ease), color .15s var(--ease); }
.nav-button:hover { background: var(--surface-2); color: var(--ink); }
.nav-button.active { background: var(--primary-soft); color: var(--primary-dark); }
.nav-label { color: var(--muted); }
.topbar { background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.status { border-radius: 999px; font-weight: 600; }
.status.off { color: var(--warn); background: var(--warn-soft); }
.status.info { color: var(--blue); background: var(--blue-soft); }
.status.danger { color: var(--danger); background: var(--danger-soft); }
.page-section { animation: pageIn .3s var(--ease) both; }

/* ---- Toast: error and success messages (top layer, top of the screen) ---- */
.toast-host { position: fixed; inset: auto; inset-block-start: calc(env(safe-area-inset-top, 0px) + 12px); inset-inline: 0; margin: 0 auto; width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 0; background: transparent; color: inherit; overflow: visible; display: flex; flex-direction: column; gap: 10px; pointer-events: none; z-index: 2147483000; }
.toast-host:empty { display: none; }
.toast-item { position: relative; pointer-events: auto; display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 12px; padding: 14px 12px 16px 14px; border-radius: 14px; box-shadow: 0 12px 34px rgba(0, 0, 0, .28), 0 2px 8px rgba(0, 0, 0, .18); overflow: hidden; animation: toastIn .24s cubic-bezier(.2, .8, .2, 1) both; }
/* A clear red in both themes (the theme's own danger colour is a pale pink in dark mode). */
.toast-item.is-error { background: #b3261e; color: #fff; border: 1px solid rgba(255, 255, 255, .28); }
:root[data-theme="dark"] .toast-item.is-error { background: #c8372d; }
.toast-item.is-ok { background: var(--ink); color: var(--bg); border: 1px solid color-mix(in srgb, var(--bg) 18%, transparent); }
.toast-item.is-leaving { animation: toastOut .2s ease-in both; }
.toast-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: color-mix(in srgb, currentColor 18%, transparent); flex: none; }
.toast-icon .ico { width: 18px; height: 18px; }
.toast-text { margin: 0; padding-block: 4px; font-size: 14.5px; font-weight: 600; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; max-height: min(40dvh, 260px); overflow-y: auto; min-width: 0; }
.toast-close { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: inherit; cursor: pointer; opacity: .85; flex: none; }
.toast-close:hover, .toast-close:focus-visible { background: color-mix(in srgb, currentColor 18%, transparent); opacity: 1; outline: none; }
.toast-close .ico { width: 16px; height: 16px; }
.toast-bar { position: absolute; inset-inline: 0; inset-block-end: 0; height: 3px; background: color-mix(in srgb, currentColor 55%, transparent); transform-origin: left center; animation: toastBar var(--toast-ms, 6000ms) linear forwards; }
[dir="rtl"] .toast-bar { transform-origin: right center; }
.toast-item.is-paused .toast-bar { animation-play-state: paused; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px) scale(.98); } }
@keyframes toastBar { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .toast-item, .toast-item.is-leaving { animation: none; } .toast-bar { display: none; } }
