/* FAHAD — design tokens, fonts, resets and shared components.
   Layout/chat styles: app.css. Settings dialog: settings.css. Both must use these tokens (no hard-coded colors). */

@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-display: swap; font-weight: 300; src: url('../vendor/fonts/ibm-plex-sans-arabic/ibm-plex-sans-arabic-arabic-300-normal.woff2') format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-display: swap; font-weight: 400; src: url('../vendor/fonts/ibm-plex-sans-arabic/ibm-plex-sans-arabic-arabic-400-normal.woff2') format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-display: swap; font-weight: 500; src: url('../vendor/fonts/ibm-plex-sans-arabic/ibm-plex-sans-arabic-arabic-500-normal.woff2') format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-display: swap; font-weight: 600; src: url('../vendor/fonts/ibm-plex-sans-arabic/ibm-plex-sans-arabic-arabic-600-normal.woff2') format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-display: swap; font-weight: 700; src: url('../vendor/fonts/ibm-plex-sans-arabic/ibm-plex-sans-arabic-arabic-700-normal.woff2') format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-display: swap; font-weight: 300; src: url('../vendor/fonts/ibm-plex-sans-arabic/ibm-plex-sans-arabic-latin-300-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-display: swap; font-weight: 400; src: url('../vendor/fonts/ibm-plex-sans-arabic/ibm-plex-sans-arabic-latin-400-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-display: swap; font-weight: 500; src: url('../vendor/fonts/ibm-plex-sans-arabic/ibm-plex-sans-arabic-latin-500-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-display: swap; font-weight: 600; src: url('../vendor/fonts/ibm-plex-sans-arabic/ibm-plex-sans-arabic-latin-600-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-display: swap; font-weight: 700; src: url('../vendor/fonts/ibm-plex-sans-arabic/ibm-plex-sans-arabic-latin-700-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ---------- Tokens: navy ('dark', the default), graphite gray ('gray') and black ('black') — all dark themes
   sharing the same teal/violet accents. ---------- */
:root,
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #060913;
  --bg-2: #0a1024;
  --bg-glow-1: rgba(46, 230, 197, 0.16);
  --bg-glow-2: rgba(139, 123, 255, 0.18);
  --surface: rgba(16, 22, 46, 0.62);
  --surface-2: rgba(26, 34, 66, 0.72);
  --surface-3: rgba(38, 48, 88, 0.78);
  --surface-solid: #0f1630;
  --surface-hover: rgba(255, 255, 255, 0.06);
  --surface-active: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.17);
  --text: #e8ecf8;
  --text-2: #aeb7d3;
  --text-3: #7b86a8;
  --accent: #2ee6c5;
  --accent-strong: #14b8a6;
  --accent-2: #8b7bff;
  --accent-contrast: #03201b;
  --accent-soft: rgba(46, 230, 197, 0.14);
  --gold: #f4c55b;
  --danger: #ff5d73;
  --danger-soft: rgba(255, 93, 115, 0.14);
  --warn: #ffb547;
  --warn-soft: rgba(255, 181, 71, 0.14);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --info: #60a5fa;
  /* Solid, calm actions (no multi-color gradients): near-white buttons with navy text, a navy student bubble. */
  --gradient-accent: linear-gradient(0deg, #e7ecf8, #e7ecf8);
  --gradient-user: linear-gradient(0deg, #1d2750, #1d2750);
  --user-text: #eef1fb;
  --on-primary: #0a1024;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 18px rgba(0, 0, 0, 0.28);
  --shadow-2: 0 18px 60px rgba(0, 0, 0, 0.5);
  --ring: 0 0 0 3px rgba(46, 230, 197, 0.35);
  --glow: 0 0 0 1px rgba(255, 255, 255, 0.16), 0 0 22px rgba(255, 255, 255, 0.05);
  --code-bg: #0b1020;
  --scrollbar: rgba(255, 255, 255, 0.14);
  --emotion-color: var(--accent); /* set by main.js per current emotion */
}

:root[data-theme='gray'] {
  /* Graphite: a deep lead gray that keeps the teal/violet accents as vivid as on navy. */
  color-scheme: dark;
  --bg: #121316;
  --bg-2: #17181c;
  --bg-glow-1: rgba(255, 255, 255, 0.04);
  --bg-glow-2: rgba(255, 255, 255, 0.03);
  --surface: rgba(30, 32, 36, 0.72);
  --surface-2: rgba(38, 40, 46, 0.8);
  --surface-3: rgba(50, 53, 60, 0.84);
  --surface-solid: #1b1c20;
  --surface-hover: rgba(255, 255, 255, 0.06);
  --surface-active: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.17);
  --text: #eceef1;
  --text-2: #b0b5bf;
  --text-3: #838994;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.34);
  --shadow-2: 0 18px 60px rgba(0, 0, 0, 0.6);
  --code-bg: #0e0f11;
  --scrollbar: rgba(255, 255, 255, 0.15);
  /* No multi-color gradients in graphite: primary actions are plain silver, the student's bubble plain gray. */
  --gradient-accent: linear-gradient(0deg, #e4e6ea, #e4e6ea);
  --gradient-user: linear-gradient(0deg, #2c2f35, #2c2f35);
  --user-text: #f1f2f4;
  --on-primary: #121316;
  --glow: 0 0 0 1px rgba(255, 255, 255, 0.16), 0 0 22px rgba(255, 255, 255, 0.05);
}

:root[data-theme='black'] {
  /* Black: true black background (OLED friendly) with near-black panels. */
  color-scheme: dark;
  --bg: #000000;
  --bg-2: #050506;
  --bg-glow-1: rgba(46, 230, 197, 0.13);
  --bg-glow-2: rgba(139, 123, 255, 0.15);
  --surface: rgba(17, 17, 20, 0.72);
  --surface-2: rgba(25, 25, 29, 0.82);
  --surface-3: rgba(36, 36, 41, 0.86);
  --surface-solid: #0d0d10;
  --surface-hover: rgba(255, 255, 255, 0.06);
  --surface-active: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.085);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #ececef;
  --text-2: #a9a9b4;
  --text-3: #7a7a86;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5), 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-2: 0 18px 60px rgba(0, 0, 0, 0.7);
  --code-bg: #0a0a0c;
  --scrollbar: rgba(255, 255, 255, 0.14);
  --gradient-accent: linear-gradient(0deg, #f0f0f2, #f0f0f2);
  --gradient-user: linear-gradient(0deg, #1e1e23, #1e1e23);
  --user-text: #f2f2f4;
  --on-primary: #000000;
}

:root {
  --font: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, 'Noto Sans Arabic', sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', 'Cascadia Code', Menlo, Consolas, monospace;
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --blur: 18px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 140ms;
  --dur: 240ms;
  --dur-slow: 420ms;
  --control-h: 40px;
  --control-h-sm: 32px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
img, svg, canvas, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 0.5em; }
p { margin: 0 0 0.75em; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-xs); }
::selection { background: rgba(46, 230, 197, 0.3); }
.icon { flex: none; }
[hidden] { display: none !important; }

* { scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Surfaces ---------- */
.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(var(--blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
  box-shadow: var(--shadow-1);
}
.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--control-h); padding: 0 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 14px; line-height: 1; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), opacity var(--dur-fast);
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.5; }
.btn-primary { background: var(--gradient-accent); border-color: transparent; color: var(--on-primary, #fff); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); }
.btn-primary:hover:not(:disabled) { background: var(--gradient-accent); filter: brightness(1.08); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); border-color: transparent; }
.btn-soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn-soft:hover:not(:disabled) { background: var(--accent-soft); filter: brightness(1.15); border-color: transparent; }
.btn-danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger); filter: brightness(1.08); }
.btn-sm { height: var(--control-h-sm); padding: 0 12px; font-size: 13px; border-radius: var(--radius-xs); }
.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; border-radius: var(--radius); }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-sm { width: var(--control-h-sm); }
.btn-block { width: 100%; }
.btn[aria-pressed='true'] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- Form controls ---------- */
.input, .select, .textarea {
  width: 100%; min-height: var(--control-h); padding: 8px 12px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background var(--dur-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }
.input[aria-invalid='true'], .textarea[aria-invalid='true'] { border-color: var(--danger); }
.input-mono { font-family: var(--font-mono); font-size: 13px; direction: ltr; text-align: left; }
.textarea { resize: vertical; min-height: 88px; line-height: 1.6; }
.select {
  appearance: none; -webkit-appearance: none; padding-inline-end: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a94b4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 10px center;
}
[dir='ltr'] .select { background-position: right 10px center; }
.select option { background: var(--surface-solid); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.field-hint { font-size: 12px; color: var(--text-3); line-height: 1.5; }
.field-error { font-size: 12px; color: var(--danger); }
.field-row { display: flex; gap: 8px; align-items: stretch; }
.field-row > .input, .field-row > .select { flex: 1; min-width: 0; }

/* Switch: <label class="switch"><input type="checkbox"><span class="switch-track"></span><span class="switch-label">…</span></label> */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative; width: 42px; height: 24px; flex: none;
  background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: 999px;
  transition: background var(--dur) var(--ease), border-color var(--dur);
}
.switch-track::after {
  content: ''; position: absolute; top: 2px; inset-inline-start: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform var(--dur) var(--ease-spring);
}
.switch input:checked + .switch-track { background: var(--accent-strong); border-color: transparent; }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
[dir='rtl'] .switch input:checked + .switch-track::after { transform: translateX(-18px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }
.switch-label { font-size: 14px; color: var(--text); }

input[type='range'].range { width: 100%; accent-color: var(--accent); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px;
  font-size: 11.5px; font-weight: 600; border-radius: 999px;
  background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ---------- Dialog base ---------- */
dialog { color: var(--text); padding: 0; border: none; background: transparent; max-width: calc(100vw - 32px); }
dialog::backdrop { background: rgba(3, 6, 16, 0.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

.confirm-dialog { width: 420px; }
.confirm-body {
  background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 22px; box-shadow: var(--shadow-2);
}
.confirm-title { font-size: 17px; }
.confirm-message { color: var(--text-2); }
.confirm-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ---------- Toasts ---------- */
.toast-host {
  position: fixed; z-index: 1000; inset-inline: 16px; bottom: calc(16px + var(--safe-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
/* Inside an open dialog: at the top of the screen, so a toast never covers the dialog's own buttons. */
.toast-host.toast-host-top { top: calc(16px + var(--safe-top, 0px)); bottom: auto; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: min(520px, 100%);
  padding: 10px 12px 10px 14px; border-radius: var(--radius); background: var(--surface-solid);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-2); font-size: 14px;
  opacity: 0; transform: translateY(10px) scale(0.98); transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.toast-enter { opacity: 1; transform: none; }
.toast-leave { opacity: 0; transform: translateY(6px); }
.toast-icon { display: inline-flex; color: var(--info); }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warn .toast-icon { color: var(--warn); }
.toast-text { flex: 1; min-width: 0; }
.toast-close { display: inline-flex; background: none; border: none; color: var(--text-3); padding: 4px; border-radius: 6px; }
.toast-close:hover { color: var(--text); background: var(--surface-hover); }

/* ---------- Utilities ---------- */
.spin { animation: fahad-spin 0.9s linear infinite; }
@keyframes fahad-spin { to { transform: rotate(360deg); } }
.muted { color: var(--text-3); }
.ltr { direction: ltr; unicode-bidi: isolate; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
:root[data-reduced-motion='true'] *, :root[data-reduced-motion='true'] *::before, :root[data-reduced-motion='true'] *::after {
  animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important;
}
