/* =========================================================
   Sara Alharbi — Portfolio
   Moody Brown palette · typography-first · RTL
   ========================================================= */

:root {
  /* Palette */
  --bg-primary: #D7C3AA;     /* Warm Beige — main background */
  --bg-secondary: #A49384;   /* Mushroom — cards / subtle containers */
  --accent-walnut: #755B4B;  /* Walnut — hover & secondary buttons */
  --text-muted: #574338;     /* Cocoa — subtitles & secondary text */
  --text-main: #3F2D24;      /* Espresso — body text */
  --text-dark: #241914;      /* Deep Brown — headings & logo */
  --border-color: #A49384;   /* Thin borders */

  /* Derived (solid, no gradients) */
  --surface: #CFBAA0;        /* a touch deeper than the background for inputs/cards */
  --surface-focus: #D2BEA4;
  --ltr-align: right;        /* alignment for LTR snippets inside the RTL page */

  /* Type */
  --font-display: "Aref Ruqaa", "IBM Plex Sans Arabic", serif;
  --font-body: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;

  /* Rhythm */
  --container: 1120px;
  --gutter: clamp(1rem, 4vw, 2.5rem);
  --section-space: clamp(5rem, 12vw, 9rem);
  --line: 1px solid var(--border-color);
  --radius: 2px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

/* ---------- Dark theme ---------- */
:root[data-theme="dark"] {
  --bg-primary: #1C1510;
  --bg-secondary: #4A3B30;
  --accent-walnut: #C9A98A;
  --text-muted: #B7A38F;
  --text-main: #E4D5C1;
  --text-dark: #F4EADB;
  --border-color: #4A3B30;
  --surface: #261C15;
  --surface-focus: #30241B;
  color-scheme: dark;
}
:root[dir="ltr"] { --ltr-align: left; }

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  font-weight: 400;
  line-height: 1.85;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
ul, ol { padding: 0; list-style: none; }
::selection { background: var(--text-dark); color: var(--bg-primary); }

:focus-visible {
  outline: 1px solid var(--text-dark);
  outline-offset: 4px;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

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

.skip-link {
  position: absolute;
  inset-inline-start: 1rem;
  top: -3rem;
  background: var(--text-dark);
  color: var(--bg-primary);
  padding: .5rem 1rem;
  z-index: 100;
  text-decoration: none;
}
.skip-link:focus { top: 1rem; }

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

[lang="en"] { font-family: var(--font-body); }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-primary);
  border-bottom: var(--line);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  min-height: 76px;
}
.logo {
  display: inline-flex;
  align-items: baseline;
  gap: .6rem;
  text-decoration: none;
  color: var(--text-dark);
  white-space: nowrap;
}
.logo-ar {
  font-family: var(--font-display);
  font-size: 1.6rem;
  line-height: 1;
}
.logo-sep { color: var(--border-color); font-weight: 300; }
.logo-en {
  font-size: .82rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.site-nav {
  display: flex;
  gap: clamp(1.25rem, 3vw, 2.5rem);
}
.site-nav a {
  position: relative;
  text-decoration: none;
  font-size: .95rem;
  color: var(--text-main);
  padding-block: .25rem;
  transition: color .25s var(--ease);
}
.site-nav a::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: -2px;
  height: 1px;
  background: var(--accent-walnut);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform .35s var(--ease);
}
.site-nav a:hover,
.site-nav a.is-active { color: var(--accent-walnut); }
.site-nav a:hover::after,
.site-nav a.is-active::after { transform: scaleX(1); }

.nav-toggle {
  display: none;
  background: none;
  border: var(--line);
  border-color: var(--text-muted);
  padding: .35rem .9rem;
  font-size: .9rem;
  cursor: pointer;
  border-radius: var(--radius);
}

/* ---------- Header tools (language + theme) ---------- */
.header-tools { display: flex; align-items: center; gap: .6rem; }
.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4rem;
  height: 2.4rem;
  padding: 0 .6rem;
  background: none;
  border: 1px solid var(--text-muted);
  border-radius: var(--radius);
  color: var(--text-main);
  font-size: .85rem;
  font-weight: 500;
  letter-spacing: .04em;
  cursor: pointer;
  transition: background .25s var(--ease), color .25s var(--ease);
}
.tool-btn:hover { background: var(--text-dark); color: var(--bg-primary); }
.tool-btn svg { width: 1.15rem; height: 1.15rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---------- Hero ---------- */
.hero {
  padding-block: clamp(3rem, 8vw, 6rem) clamp(3rem, 7vw, 5rem);
}
.hero-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  align-items: center;
  gap: clamp(2rem, 6vw, 5rem);
}
.eyebrow {
  font-size: .78rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}
.hero-title {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--text-dark);
  font-size: clamp(2.5rem, 6.5vw, 4.75rem);
  line-height: 1.3;
}
.hero-subtitle {
  margin-top: 1.25rem;
  max-width: 32rem;
  font-size: clamp(1.05rem, 1.8vw, 1.25rem);
  font-weight: 300;
  color: var(--text-muted);
  line-height: 1.9;
}
.hero-cta { display: flex; flex-wrap: wrap; gap: .85rem; margin-top: 2rem; }
.btn-solid, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0 1.75rem;
  font-size: .95rem;
  font-weight: 500;
  text-decoration: none;
  border-radius: var(--radius);
  border: 1px solid var(--text-dark);
  transition: transform .25s var(--ease), background .25s var(--ease), color .25s var(--ease);
}
.btn-solid { background: var(--text-dark); color: var(--bg-primary); }
.btn-solid:hover { background: var(--accent-walnut); border-color: var(--accent-walnut); transform: translateY(-2px); }
.btn-ghost { background: none; color: var(--text-dark); }
.btn-ghost:hover { background: var(--text-dark); color: var(--bg-primary); transform: translateY(-2px); }

/* Hero visual — animated neural network drawn in SVG */
.hero-visual { justify-self: center; width: min(100%, 26rem); }
.net { width: 100%; height: auto; overflow: visible; }
.net-lines line { stroke: var(--accent-walnut); stroke-width: 1; opacity: .25; animation: net-flow 4s ease-in-out infinite; animation-delay: var(--d, 0s); }
.net-nodes circle { fill: var(--text-dark); animation: net-node 3.2s ease-in-out infinite; animation-delay: var(--d, 0s); transform-box: fill-box; transform-origin: center; }
@keyframes net-flow { 0%, 100% { opacity: .12; } 50% { opacity: .7; } }
@keyframes net-node { 0%, 100% { transform: scale(1); opacity: .85; } 50% { transform: scale(1.35); opacity: 1; } }

/* ---------- Stats ---------- */
.stats { border-block: var(--line); background: var(--surface); }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); }
.stat {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  padding: clamp(1.5rem, 3.5vw, 2.5rem) 1rem;
  text-align: center;
}
.stat + .stat { border-inline-start: var(--line); }
.stat-num {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 5vw, 3.5rem);
  line-height: 1.1;
  color: var(--text-dark);
  direction: ltr;
}
.stat-label { font-size: .9rem; color: var(--text-muted); font-weight: 300; }

/* ---------- Chat ---------- */
.chat {
  border: var(--line);
  scroll-margin-top: 100px;
}
.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .9rem 1.5rem;
  border-bottom: var(--line);
  font-size: .82rem;
  letter-spacing: .06em;
  color: var(--text-muted);
}
.chat-label { font-weight: 500; color: var(--text-dark); }
.chat-status { transition: color .25s var(--ease); }
.chat-status.is-busy { animation: pulse 1.2s ease-in-out infinite; }
.chat-status.is-error { color: var(--text-dark); font-weight: 500; }

.chat-log {
  height: clamp(260px, 38vh, 380px);
  overflow-y: auto;
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.msg {
  max-width: 44rem;
  animation: rise .45s var(--ease) both;
}
.msg-who {
  display: block;
  font-size: .72rem;
  letter-spacing: .12em;
  color: var(--text-muted);
  margin-bottom: .35rem;
}
.msg-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-main);
}
.msg-text a { color: var(--text-dark); text-underline-offset: 3px; }

.msg-user {
  align-self: flex-end;          /* visually left in RTL */
  text-align: start;
  padding: .85rem 1.15rem;
  background: var(--bg-secondary);
  color: var(--text-dark);
  border-radius: var(--radius);
}
.msg-user .msg-who { color: var(--text-dark); opacity: .7; }
.msg-user .msg-text { color: var(--text-dark); }

.msg-bot {
  align-self: flex-start;
  padding-inline-start: 1rem;
  border-inline-start: 1px solid var(--accent-walnut);
}

.msg-error .msg-text { color: var(--text-muted); font-style: italic; }

.caret {
  display: inline-block;
  width: 1px;
  height: 1.05em;
  background: var(--text-dark);
  margin-inline-start: 2px;
  vertical-align: text-bottom;
  animation: blink .9s steps(1) infinite;
}

.thinking { display: inline-flex; gap: 5px; padding-block: .6rem; }
.thinking span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse 1.2s ease-in-out infinite;
}
.thinking span:nth-child(2) { animation-delay: .15s; }
.thinking span:nth-child(3) { animation-delay: .3s; }

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  padding: 1.1rem 1.5rem;
  border-top: var(--line);
}
.chip {
  background: transparent;
  border: var(--line);
  border-color: var(--accent-walnut);
  color: var(--text-main);
  padding: .45rem 1rem;
  border-radius: 999px;
  font-size: .88rem;
  cursor: pointer;
  transition: background .25s var(--ease), color .25s var(--ease);
}
.chip:hover { background: var(--accent-walnut); color: var(--bg-primary); }
.chip:disabled { opacity: .5; cursor: not-allowed; }

.chat-form {
  display: flex;
  border-top: var(--line);
}
.chat-form input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 0;
  padding: 1.15rem 1.5rem;
  font-size: 1rem;
  color: var(--text-dark);
  outline: none;
}
.chat-form input::placeholder { color: var(--text-muted); opacity: .8; }
.chat-form input:focus { background: var(--surface-focus); }

.btn {
  border: 0;
  cursor: pointer;
  padding: 0 2rem;
  font-size: .95rem;
  font-weight: 500;
  letter-spacing: .02em;
  transition: background .25s var(--ease), color .25s var(--ease);
}
.btn-primary { background: var(--text-dark); color: var(--bg-primary); }
.btn-primary:hover { background: var(--accent-walnut); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Sections ---------- */
.section {
  padding-block: clamp(3.5rem, 8vw, 6.5rem);
  border-bottom: var(--line);
  scroll-margin-top: 60px;
}
.section-head { margin-bottom: clamp(2rem, 5vw, 3.5rem); }
.section-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  line-height: 1.3;
  color: var(--text-dark);
}
.section-lead { margin-top: .5rem; color: var(--text-muted); font-weight: 300; }

/* ---------- Projects ---------- */
.proj-featured {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}
.proj-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin-top: 1.25rem;
}
.proj-card {
  display: flex;
  flex-direction: column;
  gap: .9rem;
  padding: clamp(1.4rem, 2.5vw, 2rem);
  border: var(--line);
  border-radius: var(--radius);
  background: var(--bg-primary);
  animation: rise .6s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 80ms);
  transition: transform .3s var(--ease), background .3s var(--ease), border-color .3s var(--ease);
}
.proj-card:hover { transform: translateY(-4px); background: var(--surface); border-color: var(--accent-walnut); }
.proj-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; min-height: 3rem; }
.project-kind { font-size: .75rem; letter-spacing: .06em; color: var(--text-muted); }
.proj-metric { display: flex; flex-direction: column; align-items: flex-end; font-size: .72rem; color: var(--text-muted); line-height: 1.3; }
.proj-metric-num { font-family: var(--font-display); font-size: 1.9rem; color: var(--text-dark); direction: ltr; }
.project-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.7rem, 3vw, 2.2rem);
  color: var(--text-dark);
  line-height: 1.2;
}
.proj-text { font-weight: 300; font-size: .98rem; margin: 0; }
.proj-grid .proj-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.proj-more summary, .cert-more summary {
  cursor: pointer;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-dark);
}
.proj-more p { margin-top: .5rem; font-size: .92rem; font-weight: 300; color: var(--text-muted); }

.tags { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .25rem; }
.tags li {
  font-size: .75rem;
  padding: .15rem .65rem;
  border: var(--line);
  color: var(--text-muted);
  border-radius: 999px;
}
.project-links { margin-top: auto; padding-top: .5rem; }
.project-links a {
  font-size: .92rem;
  font-weight: 500;
  color: var(--text-dark);
  text-decoration: none;
  border-bottom: 1px solid var(--text-dark);
  padding-bottom: 2px;
  margin-inline-end: 1rem;
  transition: color .25s var(--ease), border-color .25s var(--ease);
}
.project-links a:hover { color: var(--accent-walnut); border-color: var(--accent-walnut); }

/* ---------- Services ---------- */
.service-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
.service-card {
  padding: clamp(1.5rem, 3vw, 2.25rem);
  border: var(--line);
  border-radius: var(--radius);
  transition: transform .3s var(--ease), background .3s var(--ease);
}
.service-card:hover { transform: translateY(-4px); background: var(--surface); }
.service-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border: var(--line);
  border-radius: 50%;
  color: var(--accent-walnut);
  margin-bottom: 1.1rem;
}
.service-icon svg { width: 1.4rem; height: 1.4rem; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.service-card:hover .service-icon, .degree:hover .service-icon { background: var(--text-dark); color: var(--bg-primary); }
.service-title { font-size: 1.2rem; font-weight: 500; color: var(--text-dark); line-height: 1.5; }
.service-desc { margin-top: .4rem; font-weight: 300; color: var(--text-muted); font-size: .95rem; }

/* ---------- Education & certifications ---------- */
.edu-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; }
.degree {
  padding: clamp(1.5rem, 3vw, 2.25rem);
  border: var(--line);
  border-radius: var(--radius);
}
.degree-years { font-size: .8rem; letter-spacing: .12em; color: var(--text-muted); }
.degree-title { font-size: 1.35rem; font-weight: 500; color: var(--text-dark); line-height: 1.5; margin-top: .35rem; }
.degree-school { margin-top: .5rem; font-weight: 300; color: var(--text-muted); font-size: .95rem; }
.degree-honor {
  display: inline-block;
  margin-top: .85rem;
  padding: .25rem .9rem;
  background: var(--text-dark);
  color: var(--bg-primary);
  font-size: .82rem;
}
.cert-tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1.25rem; margin-top: 1.25rem; }
.cert-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  padding: 1.5rem .75rem;
  border: var(--line);
  border-radius: var(--radius);
  text-align: center;
  transition: transform .3s var(--ease), background .3s var(--ease);
}
.cert-tile:hover { transform: translateY(-4px); background: var(--surface); }
.cert-count { font-family: var(--font-display); font-size: 2.6rem; line-height: 1.1; color: var(--text-dark); }
.cert-name { font-size: .82rem; letter-spacing: .06em; color: var(--text-muted); }
.cert-more { margin-top: 1.5rem; }
.cert-more summary { display: inline-block; padding: .6rem 0; border-bottom: 1px solid var(--text-dark); }
.certs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 2rem;
}
.cert-col { padding-block: .5rem; padding-inline: 0 2rem; }
.cert-col + .cert-col { border-inline-start: var(--line); padding-inline-start: 2rem; }
.cert-issuer { font-size: 1.3rem; font-weight: 500; color: var(--text-dark); margin-bottom: 1rem; letter-spacing: .02em; }
.cert-col ul { direction: ltr; text-align: var(--ltr-align); }
.cert-col li { padding-block: .55rem; border-bottom: var(--line); font-size: .92rem; font-weight: 300; }
.cert-col li:last-child { border-bottom: 0; }

/* ---------- CTA ---------- */
.cta { padding-block: clamp(3.5rem, 8vw, 6rem); background: var(--surface); border-bottom: var(--line); }
.cta-inner { text-align: center; }
.cta-title { font-family: var(--font-display); font-weight: 400; font-size: clamp(2rem, 5vw, 3.4rem); line-height: 1.35; color: var(--text-dark); }
.cta .hero-cta { justify-content: center; }

/* ---------- Footer / contact ---------- */
.site-footer { border-top: var(--line); scroll-margin-top: 60px; }
.footer-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1.4fr;
  gap: clamp(2rem, 5vw, 4rem);
  padding-block: clamp(3rem, 7vw, 5rem);
}
.footer-name { font-family: var(--font-display); font-size: 1.8rem; color: var(--text-dark); }
.footer-brand p { margin-top: .75rem; max-width: 30rem; color: var(--text-muted); font-size: .95rem; }
.footer-title {
  font-size: .8rem;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.footer-col ul { display: flex; flex-direction: column; gap: .6rem; }
.footer-col a {
  color: var(--text-main);
  text-decoration: none;
  font-size: .95rem;
  overflow-wrap: anywhere;
  transition: color .25s var(--ease);
}
.footer-col a:hover { color: var(--accent-walnut); }
.footer-bottom {
  padding-block: 1.5rem;
  border-top: var(--line);
  font-size: .85rem;
  color: var(--text-muted);
}

/* ---------- Reveal on scroll ---------- */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity .8s var(--ease), transform .8s var(--ease); transition-delay: calc(var(--i, 0) * 70ms); }
.reveal.is-visible { opacity: 1; transform: none; }

/* ---------- Animations ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .hero-grid { grid-template-columns: 1fr; }
  .hero-visual { width: min(70%, 18rem); order: -1; }
  .proj-featured, .proj-grid, .service-grid { grid-template-columns: 1fr 1fr; }
  .cert-tiles { grid-template-columns: repeat(3, 1fr); }
  .certs { grid-template-columns: 1fr; }
  .cert-col, .cert-col + .cert-col { padding-inline: 0; border-inline-start: 0; }
  .cert-col + .cert-col { border-top: var(--line); padding-top: 1.5rem; margin-top: 1rem; }
}

@media (max-width: 760px) {
  .nav-toggle { display: inline-block; margin-inline-start: auto; }
  .site-nav {
    position: absolute;
    top: 100%;
    inset-inline: 0;
    flex-direction: column;
    gap: 0;
    background: var(--bg-primary);
    border-bottom: var(--line);
    padding-inline: var(--gutter);
    max-height: 0;
    overflow: hidden;
    transition: max-height .35s var(--ease);
  }
  .site-nav.is-open { max-height: 420px; }
  .site-nav a { padding-block: 1rem; border-top: var(--line); }
  .site-nav a::after { display: none; }
  .logo-en { display: none; }
  .logo-sep { display: none; }

  .proj-featured, .proj-grid, .service-grid, .edu-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(3) { border-inline-start: 0; }
  .stat:nth-child(n+3) { border-top: var(--line); }
  .cert-tiles { grid-template-columns: repeat(2, 1fr); }

  .footer-grid { grid-template-columns: 1fr; gap: 2rem; }

  .chat-head, .chat-log, .chat-suggestions { padding-inline: 1rem; }
  .chat-form input { padding-inline: 1rem; }
  .btn { padding: 0 1.25rem; }

}
