/* ============================================================
   CSC — Charter of Sapient Civilizations
   Shared Stylesheet · v1.0
   ============================================================ */

/* ---- Tokens ---- */
:root {
  --bg: #0b0f14;
  --panel: #0f1621;
  --panel-2: #141c28;
  --muted: #97a3b6;
  --text: #e9eef7;
  --brand: #79c0ff;
  --brand-2: #9ae6b4;
  --brand-3: #f7c948;
  --brand-4: #ff7b72;
  --ring: 0 0 0 3px rgba(121,192,255,.35);
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --shadow-sm: 0 4px 12px rgba(0,0,0,.2);
  --radius: 18px;
  --radius-sm: 12px;
  --maxw: 1200px;
  --card: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
  --grid-gap: clamp(14px, 2vw, 22px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f9fc;
    --panel: #ffffff;
    --panel-2: #eef2f7;
    --muted: #5b6b84;
    --text: #0e1621;
    --brand: #0067ff;
    --brand-2: #0db46e;
    --brand-3: #b98000;
    --brand-4: #c0392b;
    --shadow: 0 10px 30px rgba(0,0,0,.08);
    --shadow-sm: 0 4px 12px rgba(0,0,0,.05);
    --card: linear-gradient(180deg, rgba(0,0,0,.025), rgba(0,0,0,.01));
  }
}

/* ---- Reset / Base ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.6 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell,
        Noto Sans, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(121,192,255,.15), transparent 60%),
    radial-gradient(900px 400px at 10% 10%, rgba(154,230,180,.12), transparent 60%),
    var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, h5 { line-height: 1.2; margin: 0 0 .5em; }
p { margin: 0 0 .8em; }
p:last-child { margin-bottom: 0; }
ul, ol { padding-left: 1.5em; margin: .5em 0 .8em; }
li + li { margin-top: .3em; }

/* ---- Layout ---- */
.container {
  max-width: var(--maxw);
  margin-inline: auto;
  padding: 18px clamp(16px, 3vw, 28px);
}
.page-wrap { min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; }

/* ---- Header / Nav ---- */
header {
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: saturate(1.2) blur(10px);
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  border-bottom: 1px solid color-mix(in oklab, var(--muted) 20%, transparent);
}
.nav { display: flex; align-items: center; gap: 16px; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; letter-spacing: .2px; }
.brand .logo {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.brand small { font-weight: 500; color: var(--muted); font-size: 13px; }
.menu { display: flex; gap: 4px; align-items: center; }
.menu a {
  padding: 8px 12px; border-radius: 10px; color: var(--muted); font-size: 14px;
  transition: background .15s, color .15s; white-space: nowrap;
}
.menu a:hover,
.menu a[aria-current="page"] {
  background: color-mix(in oklab, var(--panel) 65%, transparent);
  color: var(--text);
}
.cta { display: flex; gap: 10px; }
.mobile-toggle { display: none; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid color-mix(in oklab, var(--muted) 18%, transparent);
  background: var(--panel); box-shadow: var(--shadow-sm);
  color: var(--text); font-size: 14px; font-weight: 500;
  transition: outline .1s; white-space: nowrap;
}
.btn.primary {
  background: linear-gradient(180deg,
    color-mix(in oklab, var(--brand) 30%, transparent), transparent);
  border-color: color-mix(in oklab, var(--brand) 40%, var(--panel));
}
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 9px; }
.btn:hover { outline: var(--ring); }
.quick-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ---- Page Hero (inner pages) ---- */
.page-hero {
  padding: clamp(32px, 6vw, 70px) 0 clamp(20px, 3vw, 36px);
  border-bottom: 1px solid color-mix(in oklab, var(--muted) 14%, transparent);
  margin-bottom: 4px;
}
.page-hero .kicker {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--brand); font-weight: 600; font-size: 12px;
  letter-spacing: .35px; text-transform: uppercase; margin-bottom: 10px;
}
.page-hero h1 { font-size: clamp(26px, 4vw, 46px); margin-bottom: 10px; }
.page-hero .subtitle {
  font-size: clamp(14px, 1.3vw, 17px); color: var(--muted); max-width: 72ch;
}

/* ---- Breadcrumb ---- */
.breadcrumb {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  color: var(--muted); font-size: 13px; margin-bottom: 10px;
}
.breadcrumb a:hover { color: var(--brand); }
.breadcrumb .sep { opacity: .4; }

/* ---- Hero (index) ---- */
.hero { padding: clamp(40px, 8vw, 96px) 0 40px; }
.hero-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: var(--grid-gap); align-items: center; }
.hero .kicker { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 600; letter-spacing: .24px; text-transform: uppercase; font-size: 13px; }
.title { font-size: clamp(28px, 4.2vw, 52px); line-height: 1.12; margin: 12px 0 12px; }
.subtitle { font-size: clamp(16px, 1.3vw, 18px); color: var(--muted); max-width: 64ch; }
.search {
  display: flex; gap: 8px; align-items: center;
  background: var(--panel); border: 1px solid color-mix(in oklab, var(--muted) 18%, transparent);
  border-radius: 14px; padding: 8px; margin-top: 14px; box-shadow: var(--shadow);
}
.search input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); padding: 8px 8px; font-size: 15px;
}
.hero-card {
  background: var(--card); border: 1px solid color-mix(in oklab, var(--muted) 16%, transparent);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.stat {
  background: color-mix(in oklab, var(--panel) 80%, transparent);
  border: 1px solid color-mix(in oklab, var(--muted) 16%, transparent);
  border-radius: 14px; padding: 14px;
}
.stat strong { display: block; font-size: clamp(18px, 2.8vw, 24px); }
.stat span { color: var(--muted); font-size: 12px; }

/* ---- Cards ---- */
.card {
  background: var(--card);
  border: 1px solid color-mix(in oklab, var(--muted) 16%, transparent);
  border-radius: var(--radius-sm); padding: 20px 22px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: clamp(15px, 1.6vw, 18px); }
.card > p { color: var(--muted); font-size: 14px; }
.card .meta {
  display: flex; gap: 10px; margin-top: 12px;
  color: var(--muted); font-size: 12px; flex-wrap: wrap;
}
.card-link { transition: transform .15s ease, border-color .15s ease; cursor: pointer; }
.card-link:hover {
  transform: translateY(-3px);
  border-color: color-mix(in oklab, var(--brand) 35%, var(--panel));
}

/* ---- Grids ---- */
.grid   { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--grid-gap); }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--grid-gap); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--grid-gap); }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--grid-gap); }

/* ---- Sections ---- */
section { padding: 28px 0; }
.section-hd { margin-bottom: 20px; }
.section-hd h2 { font-size: clamp(20px, 2.8vw, 26px); }
.section-hd p { color: var(--muted); font-size: 14px; }
.section-row {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 10px; margin-bottom: 20px;
}

/* ---- Pills / Tags ---- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
  border: 1px solid color-mix(in oklab, var(--muted) 16%, transparent);
  background: color-mix(in oklab, var(--panel) 70%, transparent);
  white-space: nowrap;
}
.pill.blue  { border-color: color-mix(in oklab, var(--brand) 30%, transparent);   color: var(--brand); }
.pill.green { border-color: color-mix(in oklab, var(--brand-2) 30%, transparent); color: var(--brand-2); }
.pill.amber { border-color: color-mix(in oklab, var(--brand-3) 30%, transparent); color: var(--brand-3); }
.pill.red   { border-color: color-mix(in oklab, var(--brand-4) 30%, transparent); color: var(--brand-4); }

/* ---- Chips (horizontal filter row) ---- */
.chip-row { display: flex; gap: 8px; overflow: auto; padding-bottom: 4px; scrollbar-width: thin; }
.chip {
  padding: 7px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
  border: 1px solid color-mix(in oklab, var(--muted) 20%, transparent);
  background: color-mix(in oklab, var(--panel) 70%, transparent);
  white-space: nowrap; transition: border-color .15s, color .15s, background .15s;
}
.chip.active, .chip:hover {
  border-color: color-mix(in oklab, var(--brand) 50%, var(--panel));
  color: var(--brand);
  background: color-mix(in oklab, var(--brand) 10%, var(--panel));
}

/* ---- Principle Cards ---- */
.principle-card {
  display: flex; flex-direction: column;
  background: var(--card);
  border: 1px solid color-mix(in oklab, var(--muted) 14%, transparent);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); gap: 8px;
  transition: transform .15s, border-color .15s;
}
.principle-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in oklab, var(--brand) 35%, var(--panel));
}
.principle-card .p-num {
  font-size: 11px; font-weight: 700; color: var(--brand);
  letter-spacing: .3px; text-transform: uppercase;
}
.principle-card h3 { font-size: 17px; margin-bottom: 4px; }
.principle-card .desc { color: var(--muted); font-size: 13px; line-height: 1.55; flex: 1; }
.principle-card .attrs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* ---- Domain Cards ---- */
.domain-card { border-left: 3px solid var(--brand); }
.domain-card.green  { border-left-color: var(--brand-2); }
.domain-card.amber  { border-left-color: var(--brand-3); }
.domain-card.red    { border-left-color: var(--brand-4); }
.domain-card .d-code {
  font-family: "Fira Code", "Cascadia Code", Consolas, monospace;
  font-size: 11px; font-weight: 700; color: var(--brand);
  letter-spacing: .3px; margin-bottom: 6px;
}
.domain-card.green .d-code  { color: var(--brand-2); }
.domain-card.amber .d-code  { color: var(--brand-3); }
.domain-card.red   .d-code  { color: var(--brand-4); }

/* ---- Context Cards ---- */
.context-card .c-region { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.context-card .c-trad {
  list-style: none; padding: 0; margin: 8px 0 0;
  display: flex; flex-wrap: wrap; gap: 5px;
}

/* ---- Stats Row ---- */
.stats-row { display: flex; gap: var(--grid-gap); flex-wrap: wrap; margin: 24px 0; }
.stat-box {
  flex: 1; min-width: 120px;
  background: var(--card);
  border: 1px solid color-mix(in oklab, var(--muted) 16%, transparent);
  border-radius: var(--radius-sm); padding: 16px 20px; box-shadow: var(--shadow);
}
.stat-box strong { display: block; font-size: clamp(22px, 3vw, 30px); color: var(--brand); }
.stat-box span { color: var(--muted); font-size: 12px; }

/* ---- Table ---- */
.table-wrap {
  background: var(--card);
  border: 1px solid color-mix(in oklab, var(--muted) 16%, transparent);
  border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 16px; text-align: left; border-bottom: 1px solid color-mix(in oklab, var(--muted) 14%, transparent); }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .35px; background: color-mix(in oklab, var(--panel) 60%, transparent); }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in oklab, var(--brand) 4%, transparent); }

/* ---- Callout ---- */
.callout {
  border: 1px solid color-mix(in oklab, var(--brand) 25%, transparent);
  background: color-mix(in oklab, var(--brand) 6%, transparent);
  border-radius: var(--radius-sm); padding: 14px 20px; margin: 16px 0;
}
.callout strong { color: var(--brand); }
.callout.amber {
  border-color: color-mix(in oklab, var(--brand-3) 25%, transparent);
  background: color-mix(in oklab, var(--brand-3) 6%, transparent);
}
.callout.amber strong { color: var(--brand-3); }
.callout.green {
  border-color: color-mix(in oklab, var(--brand-2) 25%, transparent);
  background: color-mix(in oklab, var(--brand-2) 6%, transparent);
}
.callout.green strong { color: var(--brand-2); }

/* ---- Step List ---- */
.step-list { list-style: none; padding: 0; counter-reset: steps; }
.step-list li {
  counter-increment: steps; position: relative;
  padding: 14px 16px 14px 52px; margin-bottom: 10px;
  background: var(--card);
  border: 1px solid color-mix(in oklab, var(--muted) 14%, transparent);
  border-radius: var(--radius-sm);
}
.step-list li::before {
  content: counter(steps);
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #000; font-weight: 700; font-size: 13px;
  display: grid; place-items: center;
}

/* ---- Code / Pre ---- */
pre, code {
  font-family: "Fira Code", "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: 13px;
}
pre {
  background: color-mix(in oklab, var(--panel) 80%, transparent);
  border: 1px solid color-mix(in oklab, var(--muted) 18%, transparent);
  border-radius: var(--radius-sm); padding: 16px 20px;
  overflow-x: auto; line-height: 1.55; margin: 12px 0;
}
code { color: var(--brand); }
pre code { color: inherit; }

/* ---- Timeline chips (index) ---- */
.timeline { display: flex; gap: 10px; overflow: auto; padding-bottom: 8px; scrollbar-width: thin; }

/* ---- Divider ---- */
.divider { border: none; border-top: 1px solid color-mix(in oklab, var(--muted) 16%, transparent); margin: 28px 0; }

/* ---- Process track (RFC, governance) ---- */
.process-track { display: flex; gap: 0; flex-wrap: wrap; margin: 20px 0; }
.process-step {
  flex: 1; min-width: 120px; position: relative;
  background: var(--card);
  border: 1px solid color-mix(in oklab, var(--muted) 14%, transparent);
  padding: 16px; text-align: center; font-size: 13px;
}
.process-step:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.process-step:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.process-step:not(:last-child) { border-right: none; }
.process-step .ps-num {
  display: block; font-size: 10px; font-weight: 700;
  color: var(--brand); letter-spacing: .3px; text-transform: uppercase; margin-bottom: 4px;
}
.process-step .ps-label { font-weight: 600; font-size: 14px; display: block; margin-bottom: 2px; }
.process-step .ps-dur { color: var(--muted); font-size: 11px; }

/* ---- Role badge ---- */
.role-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: color-mix(in oklab, var(--brand) 12%, var(--panel));
  border: 1px solid color-mix(in oklab, var(--brand) 25%, transparent);
  color: var(--brand);
}

/* ---- Evidence level bar ---- */
.ev-bar { display: flex; gap: 3px; align-items: center; margin-top: 6px; }
.ev-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: color-mix(in oklab, var(--muted) 30%, transparent);
  border: 1px solid color-mix(in oklab, var(--muted) 30%, transparent);
}
.ev-dot.filled { background: var(--brand-2); border-color: var(--brand-2); }

/* ---- Footer ---- */
footer {
  margin-top: 48px;
  border-top: 1px solid color-mix(in oklab, var(--muted) 20%, transparent);
}
.footer-grid {
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: var(--grid-gap); padding: 28px 0;
}
.footer-grid h4 { font-size: 14px; margin-bottom: 10px; }
.footer-grid ul { list-style: none; padding: 0; margin: 0; }
.footer-grid li + li { margin-top: 8px; }
.footer-grid a { color: var(--muted); font-size: 13px; transition: color .15s; }
.footer-grid a:hover { color: var(--text); }
.footer-bottom {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; padding-bottom: 28px; flex-wrap: wrap;
}

/* ---- Utils ---- */
.small  { color: var(--muted); font-size: 13px; }
.icon   { width: 18px; height: 18px; display: inline-block; flex-shrink: 0; vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.flex     { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.flex-wrap { flex-wrap: wrap; }
.text-brand  { color: var(--brand); }
.text-green  { color: var(--brand-2); }
.text-amber  { color: var(--brand-3); }
.text-red    { color: var(--brand-4); }
.text-muted  { color: var(--muted); }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0  { margin-bottom: 0 !important; }

/* ---- Language Selector ---- */
.lang-select { position: relative; }
.lang-btn {
  display: flex; align-items: center; gap: 5px;
  background: none; border: 1px solid color-mix(in oklab, var(--muted) 22%, transparent);
  border-radius: 8px; padding: 5px 10px; color: var(--muted); cursor: pointer;
  font-size: .82rem; font-weight: 500; white-space: nowrap; transition: border-color .15s, color .15s;
}
.lang-btn:hover { border-color: color-mix(in oklab, var(--brand) 50%, transparent); color: var(--brand); }
#langDropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--panel); border: 1px solid color-mix(in oklab, var(--muted) 20%, transparent);
  border-radius: 10px; list-style: none; padding: 4px; min-width: 140px; z-index: 200;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
#langDropdown.open { display: block; }
#langDropdown li button {
  display: block; width: 100%; text-align: left; background: none; border: none;
  color: var(--muted); padding: 7px 12px; border-radius: 7px; cursor: pointer; font-size: .88rem;
  transition: background .12s, color .12s;
}
#langDropdown li button:hover { background: var(--panel-2); color: var(--text); }
#langDropdown li button.active { color: var(--brand); background: color-mix(in oklab, var(--brand) 8%, var(--panel)); }

/* ---- RTL (Arabic) ---- */
[dir="rtl"] .nav { flex-direction: row-reverse; }
[dir="rtl"] .menu { flex-direction: row-reverse; }
[dir="rtl"] .cta { flex-direction: row-reverse; }
[dir="rtl"] .footer-grid { direction: rtl; text-align: right; }
[dir="rtl"] .breadcrumb { flex-direction: row-reverse; }
[dir="rtl"] #langDropdown { right: auto; left: 0; }
[dir="rtl"] #langDropdown li button { text-align: right; }
[dir="rtl"] .card, [dir="rtl"] .principle-card, [dir="rtl"] .domain-card, [dir="rtl"] .context-card { text-align: right; }
[dir="rtl"] .step-list li { text-align: right; padding-right: 52px; padding-left: 16px; }
[dir="rtl"] .step-list li::before { left: auto; right: 12px; }
[dir="rtl"] .process-step { text-align: right; }
[dir="rtl"] .flex-between { flex-direction: row-reverse; }
[dir="rtl"] .hero-grid { direction: rtl; }
[dir="rtl"] .section-row { flex-direction: row-reverse; }
[dir="rtl"] .stats-row { direction: rtl; }
[dir="rtl"] .attrs { flex-direction: row-reverse; }
[dir="rtl"] .meta { flex-direction: row-reverse; }
[dir="rtl"] th, [dir="rtl"] td { text-align: right; }

/* ---- Responsive ---- */
@media (max-width: 980px) {
  .hero-grid { grid-template-columns: 1fr; }
  .grid   { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-5 { grid-template-columns: repeat(3, 1fr); }
  .footer-grid { grid-template-columns: repeat(2, 1fr); }
  .menu { display: none; }
  .mobile-toggle { display: inline-flex; }
  .process-track { flex-direction: column; }
  .process-step { border-radius: 0 !important; border-right: 1px solid color-mix(in oklab, var(--muted) 14%, transparent) !important; border-bottom: none; }
  .process-step:first-child { border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important; }
  .process-step:last-child  { border-radius: 0 0 var(--radius-sm) var(--radius-sm) !important; border-bottom: 1px solid color-mix(in oklab, var(--muted) 14%, transparent) !important; }
}
@media (max-width: 640px) {
  .grid     { grid-template-columns: 1fr; }
  .grid-2   { grid-template-columns: 1fr; }
  .grid-4   { grid-template-columns: repeat(2, 1fr); }
  .grid-5   { grid-template-columns: repeat(2, 1fr); }
  .hero-stats { grid-template-columns: repeat(2, 1fr); }
  .footer-grid { grid-template-columns: 1fr; }
  .stats-row { gap: 10px; }
  .footer-bottom { flex-direction: column; align-items: flex-start; }
}
