:root {
  --bg: #09090b;
  --surface: rgba(24, 24, 27, 0.72);
  --surface-2: rgba(255, 255, 255, 0.035);
  --surface-3: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #fafafa;
  --muted: #a1a1aa;
  --accent: #818cf8;
  --accent-soft: rgba(129, 140, 248, 0.12);
  --btn-bg: #fafafa;
  --btn-text: #09090b;
  --btn-hover: #e4e4e7;
  --dot: rgba(255, 255, 255, 0.075);
  --glow: radial-gradient(60rem 40rem at 85% -10%, rgba(129, 140, 248, 0.13), transparent 60%);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 20px 40px -24px rgba(0, 0, 0, 0.8);
  --success: #4ade80;
  --danger: #f87171;
  --whatsapp: #22c55e;
  --radius: 16px;
  --font-en: 'Cairo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-ar: 'Cairo', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

[data-theme="light"] {
  --bg: #f6f7f9;
  --surface: rgba(255, 255, 255, 0.85);
  --surface-2: #f4f4f5;
  --surface-3: #e9e9ec;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #09090b;
  --muted: #52525b;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --btn-bg: #18181b;
  --btn-text: #fafafa;
  --btn-hover: #27272a;
  --dot: rgba(9, 9, 11, 0.07);
  --glow: radial-gradient(60rem 40rem at 85% -10%, rgba(79, 70, 229, 0.07), transparent 60%);
  --shadow: 0 1px 2px rgba(9, 9, 11, 0.04), 0 12px 32px -20px rgba(9, 9, 11, 0.15);
  --success: #15803d;
  --danger: #b91c1c;
  --whatsapp: #16a34a;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 16px; }
body {
  margin: 0;
  font-family: var(--font-en);
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background: var(--glow), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s, color 0.25s;
}
html[lang="ar"] body { font-family: var(--font-ar); }
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 22px 22px;
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 0%, #000 40%, transparent 100%);
  mask-image: radial-gradient(ellipse 80% 70% at 50% 0%, #000 40%, transparent 100%);
}
img { max-width: 100%; }
a { color: inherit; }
h1, h2, h3, h4 { letter-spacing: -0.01em; }
html[lang="ar"] h1, html[lang="ar"] h2, html[lang="ar"] h3, html[lang="ar"] h4 { letter-spacing: 0; }
.ltr { direction: ltr; unicode-bidi: embed; }
[dir="rtl"] .flip-rtl { transform: scaleX(-1); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip-link { position: absolute; inset-inline-start: 8px; top: -100px; z-index: 100; padding: 8px 12px; border-radius: 8px; background: var(--btn-bg); color: var(--btn-text); }
.skip-link:focus { top: 8px; }

/* Mode switch visibility */
[data-mode="it"] .only-dev,
[data-mode="dev"] .only-it,
html:not([lang="ar"]) .lang-ar-only { display: none !important; }

/* ---------- Layout ---------- */
.page {
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 24px;
  padding: 24px 20px;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 16px;
  align-self: start;
  padding: 22px 16px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.profile { text-align: center; }
.avatar {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  object-fit: cover;
  padding: 3px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
}
.name { margin: 12px 0 2px; font-size: 1.3rem; font-weight: 700; }
.role { margin: 0 0 8px; color: var(--accent); font-weight: 600; font-size: 0.86rem; }
.bio { margin: 0 0 14px; color: var(--muted); font-size: 0.88rem; line-height: 1.55; }

.controls, .social { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.controls { margin-bottom: 12px; }

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.seg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.seg:hover { color: var(--text); }
.seg.active { background: var(--btn-bg); color: var(--btn-text); }

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.icon-btn:hover { background: var(--surface-3); border-color: var(--border-strong); }

.toc { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 12px; }
.toc a {
  padding: 7px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
}
.toc a:hover { background: var(--surface-2); color: var(--text); }
.toc a.active { background: var(--surface-3); color: var(--text); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--btn-bg); color: var(--btn-text); border-color: var(--btn-bg); }
.btn.primary:hover { background: var(--btn-hover); border-color: var(--btn-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn:disabled { opacity: 0.6; cursor: wait; }

.link { display: inline-flex; align-items: center; gap: 6px; margin-top: auto; color: var(--accent); font-size: 0.88rem; font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.link i { font-size: 0.75rem; }
.project-links { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: auto; }
.project-links .link { margin-top: 0; }

/* ---------- Content & cards ---------- */
.content { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.card, .hero {
  padding: 28px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.muted { color: var(--muted); }

.section-title { margin: 0 0 18px; font-size: 1.55rem; font-weight: 700; line-height: 1.25; }
.section-title + .muted { margin: -8px 0 18px; }
.sub-title { margin: 22px 0 10px; font-size: 0.78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.section-title + .sub-title { margin-top: 0; }
html[lang="ar"] .sub-title { text-transform: none; letter-spacing: 0; font-size: 0.9rem; }

.card-icon {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1rem;
}

/* ---------- Hero ---------- */
.hero { padding: 32px 28px; }
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.82rem;
  font-weight: 600;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0); } 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); } }

.eyebrow { margin: 0; color: var(--muted); font-weight: 500; }
.headline { margin: 2px 0 6px; font-size: clamp(2.2rem, 5.5vw, 3.2rem); font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; }
.tagline { margin: 0 0 12px; color: var(--muted); font-size: 1.08rem; }
.lead { margin: 0 0 18px; min-height: 1.7em; font-size: 1.15rem; font-weight: 600; }
.dynamic { color: var(--accent); }
.caret { display: inline-block; width: 2px; height: 1.1em; margin-inline-start: 2px; background: var(--accent); vertical-align: text-bottom; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.highlights { list-style: none; padding: 0; margin: 0 0 22px; display: flex; flex-wrap: wrap; gap: 8px; }
.highlights li { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); font-size: 0.85rem; font-weight: 600; }
.highlights i { color: var(--accent); font-size: 0.85rem; }

.stats { list-style: none; padding: 0; margin: 0 0 24px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stats li { padding: 14px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.stats strong { display: block; font-size: 1.7rem; font-weight: 800; line-height: 1.15; letter-spacing: -0.02em; }
.stats span { color: var(--muted); font-size: 0.82rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- About ---------- */
.about-text { margin: 0; font-size: 1.02rem; line-height: 1.75; }

/* ---------- Experience ---------- */
.xp { position: relative; padding: 2px 0 20px 24px; margin-inline-start: 6px; border-inline-start: 1px solid var(--border-strong); }
[dir="rtl"] .xp { padding: 2px 24px 20px 0; }
.xp:last-child { padding-bottom: 2px; }
.xp::before { content: ""; position: absolute; inset-inline-start: -5px; top: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--bg); border: 2px solid var(--accent); }
.xp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.xp h4 { margin: 0; font-size: 1.05rem; font-weight: 700; }
.company { margin: 0; color: var(--accent); font-size: 0.9rem; font-weight: 500; }
.xp time { color: var(--muted); font-size: 0.82rem; white-space: nowrap; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); }
.xp ul { margin: 10px 0 0; padding-inline-start: 18px; color: var(--muted); }
.xp li { margin-bottom: 4px; }
details.xp summary { list-style: none; cursor: pointer; }
details.xp summary::-webkit-details-marker { display: none; }
.xp-side { display: inline-flex; align-items: center; gap: 10px; }
.chevron { color: var(--muted); font-size: 0.8rem; transition: transform 0.2s; }
details[open] .chevron { transform: rotate(180deg); }
details.xp summary:hover h4 { color: var(--accent); }

/* ---------- IT projects ---------- */
.it-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.it-card { display: flex; flex-direction: column; gap: 8px; padding: 18px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); transition: border-color 0.2s; }
.it-card:hover { border-color: var(--border-strong); }
.it-card h4 { margin: 4px 0 0; font-size: 1rem; font-weight: 700; }
.it-card p { margin: 0 0 4px; color: var(--muted); font-size: 0.9rem; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: auto 0 0; }
.tags li { font-size: 0.74rem; font-weight: 500; padding: 2px 8px; border-radius: 6px; background: var(--surface-3); color: var(--muted); }

/* ---------- Projects ---------- */
.filters { margin-bottom: 16px; flex-wrap: wrap; }
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.project { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); overflow: hidden; transition: border-color 0.2s, transform 0.2s; }
.project:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.project[hidden] { display: none; }
.project.has-thumb { grid-row: span 2; }
.project-head { display: flex; align-items: center; gap: 12px; }
.project h4 { margin: 0; font-size: 1rem; font-weight: 700; }
.project .meta { margin: 0; color: var(--muted); font-size: 0.8rem; }
.project > p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.thumb { margin: -16px -16px 2px; aspect-ratio: 16 / 10; overflow: hidden; border-bottom: 1px solid var(--border); background: var(--surface-3); }
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; transition: transform 0.4s; }
.project:hover .thumb img { transform: scale(1.03); }

.earlier { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
.earlier li { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.earlier .card-icon { width: 32px; height: 32px; border-radius: 8px; font-size: 0.85rem; }
.earlier strong { font-size: 0.92rem; font-weight: 700; margin-inline-end: 8px; }
.earlier .meta { color: var(--muted); font-size: 0.76rem; }
.earlier p { margin: 2px 0 0; color: var(--muted); font-size: 0.84rem; line-height: 1.5; }

/* ---------- Skills ---------- */
.skill-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px 24px; }
.skill-group h4 { margin: 0 0 10px; font-size: 0.95rem; font-weight: 700; }
.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); font-size: 0.84rem; font-weight: 500; }
.chips i { color: var(--muted); font-size: 0.9rem; width: 1em; text-align: center; }
.chips li:hover i { color: var(--accent); }

/* ---------- Certifications ---------- */
.certs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.cert { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.cert h4 { margin: 0; font-size: 0.92rem; font-weight: 600; line-height: 1.35; }
.cert p { margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; }

/* ---------- Contact ---------- */
.contact-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 20px; align-items: start; }
.contact-cards { display: grid; gap: 10px; }
.contact-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); text-decoration: none; transition: border-color 0.2s; min-width: 0; }
a.contact-card:hover { border-color: var(--border-strong); }
.contact-card > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.contact-card small { color: var(--muted); font-size: 0.78rem; }
.contact-card strong { font-size: 0.9rem; font-weight: 600; overflow-wrap: anywhere; }

.contact-form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 6px; }
.form-row label { font-weight: 600; font-size: 0.88rem; }
input, textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: inherit;
  font: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.7; }
textarea { resize: vertical; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.contact-form .btn { justify-self: start; }
.hp { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.form-status { margin: 0; min-height: 1.5em; font-weight: 600; font-size: 0.9rem; }
.form-status.ok { color: var(--success); }
.form-status.err { color: var(--danger); }

.footer { text-align: center; color: var(--muted); padding: 4px 0 64px; }

/* ---------- Floating buttons ---------- */
.fab {
  position: fixed;
  right: 18px;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
}
.fab:hover { transform: translateY(-2px); }
[dir="rtl"] .fab { right: auto; left: 18px; }
.whatsapp-fab { bottom: 18px; width: 52px; height: 52px; font-size: 1.5rem; color: #fff; background: var(--whatsapp); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3); }
.to-top { bottom: 80px; width: 42px; height: 42px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); backdrop-filter: blur(12px); box-shadow: var(--shadow); }
.to-top[hidden] { display: none; }

/* ---------- Section order per view ---------- */
.content > #home { order: 0; }
.content > #about { order: 1; }
.content > .footer { order: 20; }
[data-mode="it"] .content > #experience { order: 2; }
[data-mode="it"] .content > #it-projects { order: 3; }
[data-mode="it"] .content > #certs { order: 4; }
[data-mode="it"] .content > #skills { order: 5; }
[data-mode="it"] .content > #projects { order: 6; }
[data-mode="it"] .content > #contact { order: 7; }
[data-mode="dev"] .content > #projects { order: 2; }
[data-mode="dev"] .content > #skills { order: 3; }
[data-mode="dev"] .content > #experience { order: 4; }
[data-mode="dev"] .content > #certs { order: 5; }
[data-mode="dev"] .content > #it-projects { order: 6; }
[data-mode="dev"] .content > #contact { order: 7; }

.toc a[href="#about"] { order: 1; }
[data-mode="it"] .toc a[href="#experience"] { order: 2; }
[data-mode="it"] .toc a[href="#it-projects"] { order: 3; }
[data-mode="it"] .toc a[href="#certs"] { order: 4; }
[data-mode="it"] .toc a[href="#skills"] { order: 5; }
[data-mode="it"] .toc a[href="#projects"] { order: 6; }
[data-mode="dev"] .toc a[href="#projects"] { order: 2; }
[data-mode="dev"] .toc a[href="#skills"] { order: 3; }
[data-mode="dev"] .toc a[href="#experience"] { order: 4; }
[data-mode="dev"] .toc a[href="#certs"] { order: 5; }
[data-mode="dev"] .toc a[href="#it-projects"] { order: 6; }
.toc a[href="#contact"] { order: 7; }

/* ---------- Reveal ---------- */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity 0.6s ease, transform 0.6s ease; }
.reveal.visible { opacity: 1; transform: none; }

/* ---------- Responsive ---------- */
@media (max-height: 760px) and (min-width: 981px) {
  .sidebar { position: static; }
}
@media (max-width: 980px) {
  .page { grid-template-columns: 1fr; padding: 16px; }
  .sidebar { position: static; }
  .toc { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .contact-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .card, .hero { padding: 22px 16px; }
  .section-title { font-size: 1.35rem; }
  .stats { gap: 8px; }
  .stats strong { font-size: 1.35rem; }
  .stats span { font-size: 0.74rem; }
  .projects, .it-grid, .certs-grid, .skill-groups, .earlier { grid-template-columns: 1fr; }
  .project.has-thumb { grid-row: auto; }
  .hero-actions .btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
}
