/* Media Bridge components.

   Reads tokens.css only: no colour literal, no colour function here
   (tests/test_design.py). Layout uses LOGICAL properties only (inline/block,
   start/end), never left/right, so one stylesheet renders correctly under
   dir="rtl" and dir="ltr". */

/* Fonts: self-hosted, no external request. Inter for Latin, IBM Plex Sans
   Arabic for Arabic, chosen per glyph by unicode-range. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/static/fonts/inter-latin-wght.woff2) format("woff2-variations");
  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: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/static/fonts/inter-latin-ext-wght.woff2) format("woff2-variations");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url(/static/fonts/plex-arabic-400.woff2) format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-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(/static/fonts/plex-arabic-500.woff2) format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-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(/static/fonts/plex-arabic-600.woff2) format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-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(/static/fonts/plex-arabic-700.woff2) format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF,
    U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}

/* Base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-body);
}
h1, h2, h3 { line-height: var(--leading-tight); margin-block: 0 var(--space-3); }
h1 { font-size: var(--text-2xl); font-weight: var(--weight-bold); }
h2 { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
h3 { font-size: var(--text-base); font-weight: var(--weight-semibold); }
p { margin-block: 0 var(--space-3); }
p:last-child { margin-block-end: 0; }
a { color: var(--primary-ink); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
code, .mono { font-family: var(--font-mono); font-size: 0.9em; }
img, svg { display: inline-block; vertical-align: middle; }

/* Latin inside Arabic: a little smaller, so a term reads as a term. A bare
   number is never wrapped (bridge/strings.py), so figures keep their size. */
.lat { font-size: 0.9em; font-weight: var(--weight-medium); }

:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.skip {
  position: absolute;
  inset-inline-start: var(--space-4);
  inset-block-start: calc(-1 * var(--space-16));
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  border-radius: var(--radius-control);
  z-index: 10;
}
.skip:focus { inset-block-start: var(--space-2); }

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

/* Layout */

.wrap { inline-size: 100%; max-inline-size: var(--page-max); margin-inline: auto; padding-inline: var(--space-4); }
main.wrap { flex: 1; padding-block: var(--space-8) var(--space-12); }
main.narrow { max-inline-size: var(--page-narrow); }
main.medium { max-inline-size: var(--page-medium); }
main.wide { max-inline-size: var(--page-wide); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: var(--space-4); margin-block-end: var(--space-4); }
.grid2 > .card { margin-block-end: 0; }
.muted { color: var(--text-muted); }
.small { font-size: var(--text-sm); }
.center { text-align: center; }

/* Top bar */

.topbar {
  background: var(--surface);
  border-block-end: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  position: sticky;
  inset-block-start: 0;
  z-index: 5;
}
.topbar-row { display: flex; align-items: center; gap: var(--space-3); min-block-size: 56px; flex-wrap: wrap; padding-block: var(--space-1); }
.brand {
  display: inline-flex; align-items: center; gap: var(--space-2);
  color: var(--text); font-weight: var(--weight-bold); font-size: var(--text-lg);
  text-decoration: none; min-block-size: 44px;
}
.brand-mark { color: var(--primary); }
.nav { display: flex; align-items: center; gap: var(--space-1); flex-wrap: wrap; margin-inline-start: auto; }
.nav a, .nav .link {
  display: inline-flex; align-items: center; min-block-size: 44px;
  column-gap: 0.3em; /* a flex item drops the space before a Latin run */
  padding-inline: var(--space-3); border-radius: var(--radius-control);
  color: var(--text-muted); font-weight: var(--weight-medium); font-size: var(--text-sm);
  text-decoration: none;
}
.nav a:hover, .nav .link:hover { background: var(--surface-hover); color: var(--text); }
.nav a[aria-current="page"] { color: var(--primary-ink); background: var(--primary-surface); }
.nav a.btn, .nav a.btn:hover { color: var(--text-on-fill); background: var(--primary); }
.theme-toggle { inline-size: 44px; padding: 0; justify-content: center; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline-block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* Footer */

.foot { border-block-start: 1px solid var(--border); background: var(--surface); }
.foot-row { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); padding-block: var(--space-5); font-size: var(--text-sm); color: var(--text-muted); }
.foot-row p { margin: 0; }
.foot-independent { margin-inline-start: auto; display: flex; flex-direction: column; gap: var(--space-1); }

/* Cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
  margin-block-end: var(--space-4);
}
.card-head { display: flex; align-items: center; gap: var(--space-2); margin-block-end: var(--space-3); }
.card-head h2 { margin: 0; }
.card-head .icon { color: var(--primary); flex: none; }
.card-accent { border-inline-start: 4px solid var(--primary); }
.card-note { background: var(--surface-muted); box-shadow: none; }

/* Buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-block-size: var(--control-height);
  padding-inline: var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius-control);
  background: var(--primary); color: var(--text-on-fill);
  font: inherit; font-size: var(--text-base); font-weight: var(--weight-semibold);
  text-decoration: none; cursor: pointer;
  transition: background-color 120ms ease;
}
.btn:hover { background: var(--primary-hover); color: var(--text-on-fill); }
.btn:active { background: var(--primary-active); }
.btn-secondary { background: var(--surface-hover); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: var(--text-on-fill); }
.btn-danger:hover { background: var(--danger-hover); color: var(--text-on-fill); }
.btn-ghost, .btn-danger-quiet { background: transparent; color: var(--primary-ink); }
.btn-ghost:hover { background: var(--primary-surface); color: var(--primary-ink); }
.btn-danger-quiet { color: var(--danger-ink); border-color: var(--border); }
.btn-danger-quiet:hover { background: var(--danger-surface); color: var(--danger-ink); }
.btn-sm { min-block-size: 36px; padding-inline: var(--space-3); font-size: var(--text-sm); }
@media (pointer: coarse) { .btn-sm { min-block-size: var(--control-height); } }
.btn-block { inline-size: 100%; }
.link { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; color: var(--primary-ink); }
form.inline { display: inline; }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-start; margin-block-end: var(--space-4); }
.actions > form { display: flex; flex-direction: column; gap: var(--space-1); flex: 1 1 200px; }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
td .row-actions { flex-wrap: nowrap; }

/* Forms */

.form { display: flex; flex-direction: column; gap: var(--space-4); }
.form > .btn:not(.btn-block) { align-self: flex-start; }
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field-label { font-weight: var(--weight-semibold); font-size: var(--text-sm); }
.field-hint { font-size: var(--text-sm); color: var(--text-muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"],
input[type="url"], input:not([type]), select {
  inline-size: 100%;
  min-block-size: var(--control-height);
  padding-inline: var(--space-3);
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
}
input:hover, select:hover { border-color: var(--text-muted); }
input:focus-visible, select:focus-visible { border-color: var(--primary); }
input[dir="ltr"] { text-align: start; }
.check { display: flex; gap: var(--space-3); align-items: flex-start; min-block-size: 44px; padding-block: var(--space-2); }
.check input { inline-size: 20px; block-size: 20px; margin: 0; margin-block-start: 0.25em; accent-color: var(--primary); flex: none; }
.inline-form { flex-direction: row; align-items: flex-end; flex-wrap: wrap; margin-block-start: var(--space-4); }
.inline-form .field { flex: 1; min-inline-size: 180px; }

/* Alerts and form errors */

.alert {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-card);
  border-inline-start: 4px solid;
  margin-block-end: var(--space-4);
}
.alert .icon { flex: none; margin-block-start: 0.2em; }
.alert > div { min-inline-size: 0; }
.alert-danger { background: var(--danger-surface); border-color: var(--danger); color: var(--danger-ink); }
.alert-success { background: var(--success-surface); border-color: var(--success); color: var(--success-ink); }
.alert-warning { background: var(--warning-surface); border-color: var(--warning); color: var(--warning-ink); }
.alert-info { background: var(--primary-surface); border-color: var(--primary); color: var(--text); }
.alert p { margin: 0; }
.alert p + p { margin-block-start: var(--space-1); }
.warn { color: var(--warning-ink); font-weight: var(--weight-semibold); margin-block-start: var(--space-3); }

/* Copy block: the personal link, the raw key, one-time links */

.copyblock {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
  padding: var(--space-2);
  padding-inline-start: var(--space-3);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  margin-block: var(--space-3);
}
.copyblock code {
  flex: 1 1 14rem; min-inline-size: 0;
  overflow-wrap: anywhere; color: var(--text); font-size: var(--text-sm);
  text-align: start;
}
.copyblock .btn { flex: none; }

/* Badges */

.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding-inline: var(--space-2); min-block-size: 24px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  white-space: nowrap; text-decoration: none;
}
.badge-pending { background: var(--warning-surface); color: var(--warning-ink); }
.badge-active { background: var(--success-surface); color: var(--success-ink); }
.badge-rejected, .badge-disabled { background: var(--danger-surface); color: var(--danger-ink); }
.badge-neutral { background: var(--surface-hover); color: var(--text-muted); }
h1 .badge { vertical-align: middle; font-size: var(--text-sm); }

/* Tables */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); margin-block-end: var(--space-4); }
.card .table-wrap { margin-block-end: 0; }
table { inline-size: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th, td { padding: var(--space-3); text-align: start; border-block-end: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
tbody tr:last-child td { border-block-end: 0; }
th { color: var(--text-muted); font-weight: var(--weight-semibold); background: var(--surface-muted); font-size: var(--text-xs); }
th a { color: inherit; }
tbody tr:hover { background: var(--surface-hover); }
td.num, dd.num { font-variant-numeric: tabular-nums; }
td.ltr, dd.ltr { unicode-bidi: plaintext; text-align: start; }

/* Toolbar, tabs, search */

.toolbar { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; margin-block-end: var(--space-4); }
.tabs { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.tabs a {
  display: inline-flex; align-items: center; gap: 0.3em; min-block-size: 36px;
  padding-inline: var(--space-3); border-radius: var(--radius-pill);
  color: var(--text-muted); text-decoration: none; font-size: var(--text-sm); font-weight: var(--weight-medium);
}
@media (pointer: coarse) { .tabs a { min-block-size: var(--control-height); } }
.tabs a:hover { background: var(--surface-hover); color: var(--text); }
.tabs a[aria-current="page"] { background: var(--primary-surface); color: var(--primary-ink); }
.search { display: flex; gap: var(--space-2); flex: 1; min-inline-size: min(100%, 260px); }

/* Facts, stats, steps, log */

.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); margin: 0 0 var(--space-4); }
.facts dt { color: var(--text-muted); font-size: var(--text-sm); }
.facts dd { margin: 0; min-inline-size: 0; overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: var(--space-4); margin-block-end: var(--space-4); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); padding: var(--space-4) var(--space-5); display: flex; flex-direction: column; gap: var(--space-1); }
.stat-label { color: var(--text-muted); font-size: var(--text-sm); }
.stat-value { font-size: var(--text-2xl); font-weight: var(--weight-bold); }
.steps { margin: 0 0 var(--space-4); padding: 0; list-style: none; counter-reset: step; display: grid; gap: var(--space-3); }
.steps li { counter-increment: step; display: flex; gap: var(--space-3); align-items: flex-start; }
.steps li::before {
  content: counter(step);
  flex: none; inline-size: 28px; block-size: 28px; border-radius: var(--radius-pill);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary-surface); color: var(--primary-ink);
  font-weight: var(--weight-bold); font-size: var(--text-sm);
}
.log { list-style: none; margin: 0; padding: 0; font-size: var(--text-sm); }
.log li { padding-block: var(--space-2); border-block-end: 1px solid var(--border); overflow-wrap: anywhere; }
.log li:last-child { border-block-end: 0; }

/* Empty states */

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-2); padding: var(--space-8) var(--space-4); color: var(--text-muted); }
.empty .icon { color: var(--border-strong); }

/* Landing */

.hero { padding-block: var(--space-6) var(--space-8); }
.hero h1 { font-size: var(--text-3xl); max-inline-size: 22ch; }
.lead { font-size: var(--text-lg); color: var(--text-muted); max-inline-size: 42em; }
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-block-start: var(--space-5); }
.video-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3);
  aspect-ratio: 16 / 9; inline-size: 100%;
  background: var(--surface-muted);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-card);
  color: var(--text-muted); text-align: center; padding: var(--space-4);
  max-inline-size: 720px; margin-inline: auto; margin-block-end: var(--space-6);
}
.video-placeholder .icon { color: var(--primary); }

/* Error pages */

.error-page { text-align: center; padding-block: var(--space-8); }
.error-code { font-size: var(--text-3xl); font-weight: var(--weight-bold); color: var(--primary-ink); font-variant-numeric: tabular-nums; margin-block-end: var(--space-2); }
.error-page .hero-actions { justify-content: center; }

/* Small screens: 360px and up */

@media (max-width: 560px) {
  main.wrap { padding-block: var(--space-5) var(--space-8); }
  .hero h1 { font-size: var(--text-2xl); }
  .card { padding: var(--space-4); }
  .inline-form { flex-direction: column; align-items: stretch; }
  .foot-independent { margin-inline-start: 0; }
  .facts { grid-template-columns: 1fr; gap: var(--space-1); }
  .facts dd { margin-block-end: var(--space-2); }
}
