/*!
 * EW UI v1: the shared look for Enduring Word's staff tools.
 * Baseline: ewdevo (Miles, 16 Oct 2026). Tokens and components as approved in
 * _docs/ew_ui/ew_ui_preview.html ("looks really good. I think this is a good UI move.").
 *
 * How a tool uses it:
 *   - Copy this folder's ew-ui.css (and ew-ui.js for the theme toggle) into the tool. Each tool pins its
 *     own copy of a numbered version, so changing one tool never breaks another.
 *   - Load Lato 400/700/900 (Google Fonts) before this file.
 *   - Everything is prefixed: tokens are --ew-*, classes are .ew-*. Nothing here styles bare elements
 *     except inside .ew-app (the page body opt-in), so it can sit beside an existing stylesheet.
 *
 * Theme: light by default; dark follows the system setting unless the page sets
 * <html data-theme="light|dark"> (ew-ui.js does this from the header toggle). .ew-theme-light and
 * .ew-theme-dark pin one region to a theme (e.g. eweditor's editing page stays light).
 *
 * Color rules that are easy to break:
 *   --ew-accent-text (#CC8400) is for large bold numbers on a white card only (3.06:1). On the page
 *   background, tinted surfaces, small text, or hover/selected states use --ew-accent-text-deep (4.05:1).
 *   Buttons use --ew-blue-strong, not --ew-blue: white on #449AE3 is 3.0:1, on #2A74BA it is 4.9:1.
 *
 * The dark token set appears twice (system setting and explicit choice). tests/check_tokens.py fails
 * if the two copies drift apart. Edit both, or neither.
 */

/* ========== Tokens: light ========== */
:root, .ew-theme-light {
  --ew-blue: #449AE3;           /* enduringword.com site blue: accents, focus, links on light */
  --ew-blue-strong: #2A74BA;    /* buttons: white text passes 4.9:1 */
  --ew-blue-strong-hover: #22629F;
  --ew-blue-soft: #E8F4FC;
  --ew-link: #1F6AAF;
  --ew-navy: #1B3A5C;           /* occasional headings and accents only */
  --ew-ink: #1F2933;
  --ew-muted: #5B6875;
  --ew-line: #D7DEE5;
  --ew-bg: #F8FAFC;
  --ew-surface: #FFFFFF;
  --ew-surface-2: #F4F7FA;
  --ew-focus: #449AE3;
  --ew-on-strong: #FFFFFF;
  --ew-accent: #FBB040;         /* the one attention color: fills, marks, highlights */
  --ew-on-accent: #2B1D04;
  --ew-accent-text: #CC8400;
  --ew-accent-text-deep: #B36F00;
  --ew-accent-soft: #FFF4E0;
  --ew-bright: #029CE9;         /* second attention color: live, active, progress */
  --ew-on-bright: #04263A;
  --ew-bright-soft: #E2F4FD;
  --ew-shadow: 0 1px 2px rgba(20, 40, 60, .06), 0 2px 8px rgba(20, 40, 60, .05);

  /* Status colors, the same meaning in every tool. */
  --ew-st-none-bg: #EEF1F4;  --ew-st-none-fg: #4A5763;   /* not started */
  --ew-st-prog-bg: #E3F0FB;  --ew-st-prog-fg: #1F5F99;   /* in progress */
  --ew-st-rev-bg:  #FDE9DA;  --ew-st-rev-fg:  #9A4A12;   /* needs review: orange, apart from the gold (Miles, 18 Oct) */
  --ew-st-ok-bg:   #E3F3EA;  --ew-st-ok-fg:   #22693F;   /* ready / published */
  --ew-st-err-bg:  #FBE7E7;  --ew-st-err-fg:  #A4282B;   /* error */
  color-scheme: light;
}

/* Theme-independent tokens. */
:root {
  --ew-font: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ew-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ew-s1: 4px; --ew-s2: 8px; --ew-s3: 16px; --ew-s4: 24px; --ew-s5: 32px; --ew-s6: 48px;
  --ew-r-sm: 8px; --ew-r-md: 10px;
  --ew-max: 1120px;
  --ew-phone: 760px;            /* documentation only: media queries can't read custom properties */
}

/* ========== Tokens: dark (system setting) ========== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* ew-dark-tokens:start */
    --ew-blue: #5AA9EC; --ew-blue-strong: #2A74BA; --ew-blue-strong-hover: #22629F; --ew-blue-soft: #15314A;
    --ew-link: #7DBDF2; --ew-navy: #A9C8E8; --ew-ink: #E4EBF1; --ew-muted: #9BA9B6; --ew-line: #2A3947;
    --ew-bg: #0E161E; --ew-surface: #15202B; --ew-surface-2: #1B2834; --ew-focus: #7DBDF2; --ew-on-strong: #FFFFFF;
    --ew-accent: #FBB040; --ew-on-accent: #2B1D04; --ew-accent-text: #FBB040; --ew-accent-text-deep: #FBB040; --ew-accent-soft: #3A2A0E;
    --ew-bright: #029CE9; --ew-on-bright: #04263A; --ew-bright-soft: #0B2B40;
    --ew-shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --ew-st-none-bg: #222D38; --ew-st-none-fg: #B5C1CC;
    --ew-st-prog-bg: #16324B; --ew-st-prog-fg: #9CCBF3;
    --ew-st-rev-bg:  #3D2415; --ew-st-rev-fg:  #F5B48A;
    --ew-st-ok-bg:   #143324; --ew-st-ok-fg:   #8FD5AE;
    --ew-st-err-bg:  #3D1A1C; --ew-st-err-fg:  #F3A3A5;
    color-scheme: dark;
    /* ew-dark-tokens:end */
  }
  /* A region pinned light inside a dark page. */
  :root:not([data-theme="light"]) .ew-theme-light { color-scheme: light; }
}

/* ========== Tokens: dark (explicit choice) ========== */
:root[data-theme="dark"], .ew-theme-dark {
  /* ew-dark-tokens:start */
  --ew-blue: #5AA9EC; --ew-blue-strong: #2A74BA; --ew-blue-strong-hover: #22629F; --ew-blue-soft: #15314A;
  --ew-link: #7DBDF2; --ew-navy: #A9C8E8; --ew-ink: #E4EBF1; --ew-muted: #9BA9B6; --ew-line: #2A3947;
  --ew-bg: #0E161E; --ew-surface: #15202B; --ew-surface-2: #1B2834; --ew-focus: #7DBDF2; --ew-on-strong: #FFFFFF;
  --ew-accent: #FBB040; --ew-on-accent: #2B1D04; --ew-accent-text: #FBB040; --ew-accent-text-deep: #FBB040; --ew-accent-soft: #3A2A0E;
  --ew-bright: #029CE9; --ew-on-bright: #04263A; --ew-bright-soft: #0B2B40;
  --ew-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --ew-st-none-bg: #222D38; --ew-st-none-fg: #B5C1CC;
  --ew-st-prog-bg: #16324B; --ew-st-prog-fg: #9CCBF3;
  --ew-st-rev-bg:  #3D2415; --ew-st-rev-fg:  #F5B48A;
  --ew-st-ok-bg:   #143324; --ew-st-ok-fg:   #8FD5AE;
  --ew-st-err-bg:  #3D1A1C; --ew-st-err-fg:  #F3A3A5;
  color-scheme: dark;
  /* ew-dark-tokens:end */
}

/* ========== Base (opt-in: put class="ew-app" on <body>) ==========
   Element rules sit inside :where() so any component class (.ew-btn on an <a>, a tool's own h2 class) wins. */
.ew-app {
  margin: 0; background: var(--ew-bg); color: var(--ew-ink);
  font-family: var(--ew-font); font-size: 16px; line-height: 1.6;
  -webkit-font-smoothing: antialiased; text-size-adjust: 100%;
}
.ew-app *, .ew-app *::before, .ew-app *::after { box-sizing: border-box; }
.ew-app :where(h1, h2, h3) { line-height: 1.25; text-wrap: balance; margin: 0; }
.ew-app :where(h1) { font-size: 1.75rem; font-weight: 900; }
.ew-app :where(h2) { font-size: 1.25rem; font-weight: 900; }
.ew-app :where(h3) { font-size: 1rem; font-weight: 700; }
.ew-app :where(p) { margin: 0; }
.ew-app :where(a) { color: var(--ew-link); }
.ew-app :where(code, kbd) { font-family: var(--ew-mono); font-size: .88em; }
.ew-app :focus-visible { outline: 3px solid var(--ew-focus); outline-offset: 2px; border-radius: 4px; }
.ew-theme-light, .ew-theme-dark { background: var(--ew-bg); color: var(--ew-ink); }
@media (prefers-reduced-motion: reduce) {
  .ew-app *, .ew-app *::before, .ew-app *::after { transition: none !important; animation: none !important; }
}
.ew-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ========== Layout ========== */
.ew-wrap {
  max-width: var(--ew-max); margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.ew-main { padding-block: var(--ew-s5) var(--ew-s6); display: grid; gap: var(--ew-s4); }
.ew-stack { display: grid; gap: var(--ew-s3); min-width: 0; }
.ew-row { display: flex; flex-wrap: wrap; gap: var(--ew-s2) var(--ew-s3); align-items: center; }
.ew-spread { display: flex; flex-wrap: wrap; gap: var(--ew-s2) var(--ew-s3); align-items: center; justify-content: space-between; }
.ew-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--ew-s4); }
.ew-eyebrow { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ew-muted); }
.ew-muted { color: var(--ew-muted); }
.ew-note { font-size: .85rem; color: var(--ew-muted); }
.ew-page-head { display: flex; flex-wrap: wrap; gap: var(--ew-s2) var(--ew-s3); align-items: end; justify-content: space-between; }
.ew-page-head p { color: var(--ew-muted); max-width: 66ch; }

/* Sidebar layout: a nav or file tree beside the work. On a phone the sidebar becomes a drawer
   (add .is-open to .ew-layout-sidebar to show it; ew-ui.js wires [data-ew-drawer-toggle]). */
.ew-layout-sidebar { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: var(--ew-s4); align-items: start; }
.ew-sidebar {
  position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto;
  background: var(--ew-surface); border: 1px solid var(--ew-line); border-radius: var(--ew-r-md); padding: var(--ew-s2);
}
.ew-sidebar a, .ew-sidebar button.ew-side-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 7px 10px; border-radius: var(--ew-r-sm); border: 0; background: none;
  font: inherit; font-size: .92rem; color: var(--ew-ink); text-decoration: none; cursor: pointer;
}
.ew-sidebar a:hover, .ew-sidebar button.ew-side-item:hover { background: var(--ew-surface-2); }
.ew-sidebar [aria-current="page"], .ew-sidebar [aria-current="true"] { background: var(--ew-blue-soft); color: var(--ew-link); font-weight: 700; }
.ew-sidebar-title { font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ew-muted); padding: 10px 10px 4px; }
.ew-drawer-scrim { display: none; }

/* ========== Header ========== */
.ew-app::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30;
  background: var(--ew-surface);
}
.ew-header {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: var(--ew-surface); border-bottom: 1px solid var(--ew-line);
}
.ew-header-inner { display: flex; align-items: center; justify-content: space-between; gap: var(--ew-s3); padding-block: 10px; }
.ew-brand { display: flex; align-items: center; gap: 10px; color: var(--ew-ink); text-decoration: none; min-width: 0; }
.ew-mark {
  display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: var(--ew-r-sm);
  background: var(--ew-blue); color: #fff; font-weight: 900; font-size: .8rem; letter-spacing: .02em;
}
.ew-brand-name { font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ew-brand-name span { font-weight: 400; color: var(--ew-muted); }
.ew-head-right { display: flex; align-items: center; gap: var(--ew-s2); }
.ew-nav { display: flex; gap: 2px; }
.ew-nav a {
  color: var(--ew-muted); text-decoration: none; font-weight: 700; font-size: .9rem;
  padding: 6px 12px; border-radius: var(--ew-r-sm);
}
.ew-nav a:hover { color: var(--ew-ink); background: var(--ew-surface-2); }
.ew-nav a[aria-current="page"] { color: var(--ew-link); background: var(--ew-blue-soft); }

.ew-icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0;
  border: 1px solid var(--ew-line); border-radius: var(--ew-r-sm);
  background: var(--ew-surface); color: var(--ew-ink); cursor: pointer;
}
.ew-icon-btn:hover { background: var(--ew-surface-2); }
.ew-icon-btn svg { width: 18px; height: 18px; }
/* Theme toggle: shows a moon in light, a sun in dark (both icons in the markup; CSS picks one). */
.ew-theme-toggle .ew-icon-sun { display: none; }
:root[data-theme="dark"] .ew-theme-toggle .ew-icon-sun { display: block; }
:root[data-theme="dark"] .ew-theme-toggle .ew-icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ew-theme-toggle .ew-icon-sun { display: block; }
  :root:not([data-theme="light"]) .ew-theme-toggle .ew-icon-moon { display: none; }
}

/* User menu: <div class="ew-user-menu"><button class="ew-user" aria-expanded>...</button><div class="ew-menu" hidden>...</div></div> */
.ew-user-menu { position: relative; }
.ew-user {
  display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px;
  border: 1px solid var(--ew-line); border-radius: 999px; background: var(--ew-surface);
  color: var(--ew-ink); font: inherit; font-size: .88rem; cursor: pointer;
}
.ew-user:hover { background: var(--ew-surface-2); }
.ew-avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--ew-blue-soft); color: var(--ew-link); font-weight: 900; font-size: .75rem;
}
.ew-role { font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ew-muted); }
.ew-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 220px;
  background: var(--ew-surface); border: 1px solid var(--ew-line); border-radius: var(--ew-r-md);
  box-shadow: var(--ew-shadow); padding: 6px; display: grid; gap: 2px;
}
.ew-menu[hidden] { display: none; }
.ew-menu-head { padding: 8px 10px; border-bottom: 1px solid var(--ew-line); margin-bottom: 4px; font-size: .88rem; }
.ew-menu-head small { display: block; color: var(--ew-muted); }
.ew-menu a, .ew-menu button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 6px;
  background: none; font: inherit; font-size: .92rem; color: var(--ew-ink); text-decoration: none; cursor: pointer;
}
.ew-menu a:hover, .ew-menu button:hover { background: var(--ew-surface-2); }
.ew-menu-btn { display: none; }

/* ========== Panels and cards ========== */
.ew-panel {
  background: var(--ew-surface); border: 1px solid var(--ew-line); border-radius: var(--ew-r-md);
  padding: var(--ew-s4); display: grid; gap: var(--ew-s3); min-width: 0;
}
.ew-panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--ew-s3); flex-wrap: wrap; }
.ew-panel-head p { color: var(--ew-muted); font-size: .9rem; }
.ew-card { background: var(--ew-surface); border: 1px solid var(--ew-line); border-radius: var(--ew-r-md); padding: var(--ew-s3); display: grid; gap: 6px; min-width: 0; color: var(--ew-ink); text-decoration: none; }
a.ew-card:hover { border-color: var(--ew-blue); box-shadow: var(--ew-shadow); }
.ew-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: var(--ew-s3); }

/* ========== Buttons ========== */
.ew-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 18px; border-radius: var(--ew-r-sm);
  font: inherit; font-family: var(--ew-font); font-weight: 700; font-size: .95rem; line-height: 1.2;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  border: 1px solid transparent; transition: background .15s, border-color .15s;
}
.ew-btn svg { width: 16px; height: 16px; }
.ew-btn-primary { background: var(--ew-blue-strong); color: var(--ew-on-strong); }
.ew-btn-primary:hover { background: var(--ew-blue-strong-hover); }
.ew-btn-secondary { background: var(--ew-surface); color: var(--ew-ink); border-color: var(--ew-line); }
.ew-btn-secondary:hover { background: var(--ew-surface-2); }
.ew-btn-ghost { background: transparent; color: var(--ew-link); }
.ew-btn-ghost:hover { background: var(--ew-blue-soft); }
.ew-btn-danger { background: var(--ew-surface); color: var(--ew-st-err-fg); border-color: var(--ew-st-err-fg); }
.ew-btn-danger:hover { background: var(--ew-st-err-bg); }
.ew-btn[disabled], .ew-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.ew-btn-sm { min-height: 32px; padding: 4px 12px; font-size: .85rem; }
.ew-btn-block { width: 100%; }

/* ========== Forms ========== */
.ew-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--ew-s3) var(--ew-s4); }
.ew-field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.ew-field.ew-full { grid-column: 1 / -1; }
.ew-field > label, .ew-label { font-weight: 700; font-size: .9rem; }
.ew-hint { font-size: .82rem; color: var(--ew-muted); }
.ew-err { font-size: .82rem; color: var(--ew-st-err-fg); font-weight: 700; }
.ew-input, .ew-select, .ew-textarea {
  width: 100%; font: inherit; font-family: var(--ew-font); font-size: .95rem; color: var(--ew-ink);
  background: var(--ew-surface); border: 1px solid var(--ew-line); border-radius: var(--ew-r-sm);
  padding: 9px 12px; min-height: 42px;
}
.ew-textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.ew-input::placeholder, .ew-textarea::placeholder { color: var(--ew-muted); opacity: 1; }
.ew-input:focus, .ew-select:focus, .ew-textarea:focus {
  outline: none; border-color: var(--ew-blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ew-blue) 30%, transparent);
}
.ew-input.is-error, .ew-select.is-error, .ew-textarea.is-error { border-color: var(--ew-st-err-fg); }
.ew-input[disabled], .ew-select[disabled], .ew-textarea[disabled] { background: var(--ew-surface-2); color: var(--ew-muted); cursor: not-allowed; }
.ew-check { display: flex; gap: 10px; align-items: center; font-size: .95rem; }
.ew-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--ew-blue-strong); flex: none; }
.ew-file {
  display: flex; align-items: center; gap: var(--ew-s3); flex-wrap: wrap;
  border: 1.5px dashed var(--ew-line); border-radius: var(--ew-r-md); padding: var(--ew-s3);
  background: var(--ew-surface-2);
}
.ew-file p { color: var(--ew-muted); font-size: .9rem; }
.ew-file.is-dragover { border-color: var(--ew-blue); background: var(--ew-blue-soft); }
.ew-toolbar {
  display: flex; flex-wrap: wrap; gap: 2px; padding: 4px;
  border: 1px solid var(--ew-line); border-bottom: 0; border-radius: var(--ew-r-sm) var(--ew-r-sm) 0 0;
  background: var(--ew-surface-2);
}
.ew-toolbar button {
  font: inherit; font-weight: 700; font-size: .85rem; min-width: 34px; height: 32px;
  border: 0; border-radius: 6px; background: transparent; color: var(--ew-ink); cursor: pointer;
}
.ew-toolbar button:hover { background: var(--ew-surface); }
.ew-toolbar button[aria-pressed="true"] { background: var(--ew-blue-soft); color: var(--ew-link); }
.ew-toolbar + .ew-textarea { border-radius: 0 0 var(--ew-r-sm) var(--ew-r-sm); }

/* Choice chips: a row of one-tap options (e.g. ewproof's change categories). */
.ew-choices { display: flex; flex-wrap: wrap; gap: 6px; }
.ew-choice {
  font: inherit; font-size: .85rem; font-weight: 700; padding: 4px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--ew-line); background: var(--ew-surface); color: var(--ew-ink);
}
.ew-choice:hover { background: var(--ew-surface-2); }
.ew-choice[aria-pressed="true"], .ew-choice[aria-checked="true"] { background: var(--ew-blue-soft); border-color: var(--ew-blue); color: var(--ew-link); }

/* ========== Status chips ========== */
.ew-chip {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: .8rem; font-weight: 700; line-height: 1.5; padding: 3px 10px; border-radius: 999px; text-decoration: none;
}
.ew-chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.ew-chip-none { background: var(--ew-st-none-bg); color: var(--ew-st-none-fg); }
.ew-chip-none::before { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; }
.ew-chip-prog { background: var(--ew-st-prog-bg); color: var(--ew-st-prog-fg); }
.ew-chip-rev  { background: var(--ew-st-rev-bg);  color: var(--ew-st-rev-fg); }
.ew-chip-ok   { background: var(--ew-st-ok-bg);   color: var(--ew-st-ok-fg); }
.ew-chip-err  { background: var(--ew-st-err-bg);  color: var(--ew-st-err-fg); }

/* ========== Metrics ========== */
.ew-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--ew-s3); }
.ew-metric { border: 1px solid var(--ew-line); border-radius: var(--ew-r-md); padding: var(--ew-s3); display: grid; gap: 2px; background: var(--ew-surface); min-width: 0; }
.ew-metric > span { font-size: .8rem; color: var(--ew-muted); font-weight: 700; }
.ew-metric > strong { font-size: 1.75rem; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.2; }
.ew-metric > small { font-size: .8rem; color: var(--ew-muted); }
.ew-metric.is-key { border-color: var(--ew-accent); box-shadow: inset 0 3px 0 var(--ew-accent); }
.ew-metric.is-key > strong { color: var(--ew-accent-text); }   /* white card + large bold only: see the header rule */

/* ========== Attention: gold and bright blue ========== */
.ew-badge-accent, .ew-badge-bright {
  display: inline-flex; align-items: center; gap: 6px; font-size: .72rem; font-weight: 900;
  letter-spacing: .05em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px;
}
.ew-badge-accent { background: var(--ew-accent); color: var(--ew-on-accent); }
.ew-badge-bright { background: var(--ew-bright); color: var(--ew-on-bright); }
.ew-count {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--ew-accent); color: var(--ew-on-accent); font-size: .78rem; font-weight: 900; font-variant-numeric: tabular-nums;
}
.ew-callout {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: var(--ew-r-sm);
  background: var(--ew-accent-soft); border-left: 4px solid var(--ew-accent); font-size: .92rem;
}
.ew-big-accent { font-size: 2.5rem; font-weight: 900; line-height: 1; color: var(--ew-accent-text); font-variant-numeric: tabular-nums; }
.ew-big-bright { font-size: 2.5rem; font-weight: 900; line-height: 1; color: var(--ew-bright); font-variant-numeric: tabular-nums; }
.ew-live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ew-bright); box-shadow: 0 0 0 4px var(--ew-bright-soft); flex: none; display: inline-block; }
.ew-unread { width: 9px; height: 9px; border-radius: 50%; background: var(--ew-bright); flex: none; display: inline-block; }
.ew-progress { height: 8px; border-radius: 999px; background: var(--ew-surface-2); overflow: hidden; }
.ew-progress > i { display: block; height: 100%; width: var(--ew-value, 0%); background: var(--ew-bright); border-radius: inherit; }

/* ========== Alerts ========== */
.ew-alert {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px;
  padding: 12px 16px; border-radius: var(--ew-r-sm); font-size: .92rem;
}
.ew-alert > :only-child { grid-column: 1 / -1; }
.ew-alert b { display: block; }
.ew-alert svg { width: 18px; height: 18px; margin-top: 3px; }
.ew-alert-info { background: var(--ew-st-prog-bg); color: var(--ew-st-prog-fg); }
.ew-alert-ok   { background: var(--ew-st-ok-bg);   color: var(--ew-st-ok-fg); }
.ew-alert-warn { background: var(--ew-st-rev-bg);  color: var(--ew-st-rev-fg); }
.ew-alert-err  { background: var(--ew-st-err-bg);  color: var(--ew-st-err-fg); }

/* ========== Tabs ========== */
.ew-tabs { display: flex; gap: var(--ew-s1); border-bottom: 1px solid var(--ew-line); overflow-x: auto; }
.ew-tabs > a, .ew-tabs > button {
  font: inherit; font-weight: 700; font-size: .92rem; color: var(--ew-muted); text-decoration: none;
  background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 14px; cursor: pointer; white-space: nowrap;
}
.ew-tabs > a:hover, .ew-tabs > button:hover { color: var(--ew-ink); }
.ew-tabs > [aria-selected="true"], .ew-tabs > [aria-current="page"] { color: var(--ew-ink); border-bottom-color: var(--ew-blue); }

/* ========== Empty, loading, and error states ========== */
.ew-state {
  border: 1px dashed var(--ew-line); border-radius: var(--ew-r-md); padding: var(--ew-s4) var(--ew-s3);
  text-align: center; display: grid; gap: 8px; justify-items: center; color: var(--ew-muted); font-size: .92rem;
}
.ew-state strong { color: var(--ew-ink); }
.ew-state.is-error { border-color: var(--ew-st-err-fg); }
.ew-spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--ew-line); border-top-color: var(--ew-blue); animation: ew-spin .9s linear infinite; }
@keyframes ew-spin { to { transform: rotate(360deg); } }
.ew-skel { height: 10px; width: 80%; border-radius: 5px; background: var(--ew-surface-2); }

/* ========== Tables (fold to cards in a narrow container) ========== */
.ew-table-wrap { overflow-x: auto; border: 1px solid var(--ew-line); border-radius: var(--ew-r-md); background: var(--ew-surface); container-type: inline-size; }
table.ew-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.ew-table th {
  text-align: left; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ew-muted);
  font-weight: 700; padding: 10px 14px; background: var(--ew-surface-2); border-bottom: 1px solid var(--ew-line);
}
table.ew-table td { padding: 12px 14px; border-bottom: 1px solid var(--ew-line); vertical-align: middle; }
table.ew-table tbody tr:last-child td { border-bottom: 0; }
table.ew-table .ew-cell-title { font-weight: 700; display: block; }
table.ew-table .ew-cell-sub { font-size: .82rem; color: var(--ew-muted); }
table.ew-table td.ew-num, table.ew-table th.ew-num { text-align: right; font-variant-numeric: tabular-nums; }
table.ew-table td.ew-act { text-align: right; }
table.ew-table tr.is-needs td:first-child { box-shadow: inset 3px 0 0 var(--ew-st-rev-fg); }
table.ew-table tr.is-failed td:first-child { box-shadow: inset 3px 0 0 var(--ew-st-err-fg); }
table.ew-table tbody tr.is-clickable { cursor: pointer; }
table.ew-table tbody tr.is-clickable:hover td { background: var(--ew-surface-2); }
/* Add .ew-table-fold to fold into cards below 560px of container width. Give each <td> a data-label. */
@container (max-width: 560px) {
  table.ew-table-fold thead { display: none; }
  table.ew-table-fold, table.ew-table-fold tbody, table.ew-table-fold tr, table.ew-table-fold td { display: block; width: 100%; }
  table.ew-table-fold tr { padding: 12px 14px; border-bottom: 1px solid var(--ew-line); }
  table.ew-table-fold tbody tr:last-child { border-bottom: 0; }
  table.ew-table-fold td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  table.ew-table-fold td[data-label]::before { content: attr(data-label); font-size: .78rem; font-weight: 700; color: var(--ew-muted); text-align: left; }
  table.ew-table-fold td:first-child { display: block; padding-bottom: 8px; text-align: left; }
  table.ew-table-fold td.ew-act { justify-content: flex-end; padding-top: 8px; }
  table.ew-table-fold tr.is-needs td:first-child, table.ew-table-fold tr.is-failed td:first-child { box-shadow: none; }
  table.ew-table-fold tr.is-needs { box-shadow: inset 3px 0 0 var(--ew-st-rev-fg); }
  table.ew-table-fold tr.is-failed { box-shadow: inset 3px 0 0 var(--ew-st-err-fg); }
}

/* ========== Side-by-side compare ========== */
.ew-compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--ew-line); border-radius: var(--ew-r-md); overflow: hidden; background: var(--ew-surface); }
.ew-compare > * { padding: var(--ew-s3); display: grid; gap: 8px; align-content: start; min-width: 0; }
.ew-compare > * + * { border-left: 1px solid var(--ew-line); }
/* Labels and text styles apply to the compare columns themselves, never to content inside them (a tool's
   rendered HTML keeps its own h3, p, and mark). */
.ew-compare > * > h3, .ew-compare-label { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ew-muted); font-weight: 700; margin: 0; }
.ew-compare > * > p { font-size: .95rem; }
mark.ew-mark-rev { background: var(--ew-st-rev-bg); color: inherit; border-radius: 3px; padding: 0 2px; }
ins.ew-ins { background: var(--ew-st-ok-bg); color: var(--ew-st-ok-fg); text-decoration: none; border-radius: 3px; padding: 0 2px; }
del.ew-del { background: var(--ew-st-err-bg); color: var(--ew-st-err-fg); border-radius: 3px; padding: 0 2px; }
/* Rows of aligned pairs: <div class="ew-compare ew-compare-rows"><div class="ew-compare-row"><div>EN</div><div>XX</div></div>...</div> */
.ew-compare-rows { display: block; }
.ew-compare-rows > .ew-compare-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 0; border-left: 0; }
.ew-compare-rows > .ew-compare-row + .ew-compare-row { border-top: 1px solid var(--ew-line); }
.ew-compare-rows > .ew-compare-row > * { padding: 12px var(--ew-s3); min-width: 0; }
.ew-compare-rows > .ew-compare-row > * + * { border-left: 1px solid var(--ew-line); }
.ew-compare-row.is-selected { background: var(--ew-blue-soft); }
.ew-compare [dir="rtl"] { text-align: right; }

/* ========== Phone (<= 760px) ========== */
@media (max-width: 760px) {
  .ew-nav, .ew-user .ew-user-text { display: none; }
  .ew-menu-btn { display: inline-grid; }
  .ew-grid-2, .ew-form { grid-template-columns: minmax(0, 1fr); }
  .ew-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ew-panel { padding: var(--ew-s3); }
  .ew-compare, .ew-compare-rows > .ew-compare-row { grid-template-columns: minmax(0, 1fr); }
  .ew-compare > * + *, .ew-compare-rows > .ew-compare-row > * + * { border-left: 0; border-top: 1px solid var(--ew-line); }
  .ew-layout-sidebar { grid-template-columns: minmax(0, 1fr); }
  .ew-layout-sidebar > .ew-sidebar {
    position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: min(86vw, 320px); max-height: none;
    border-radius: 0; border-width: 0 1px 0 0; padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
    transform: translateX(-100%); transition: transform .2s; visibility: hidden;
  }
  .ew-layout-sidebar.is-open > .ew-sidebar { transform: none; visibility: visible; }
  .ew-layout-sidebar.is-open > .ew-drawer-scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, .35); }
  /* The header nav moves into an open .ew-menu-panel. */
  .ew-menu-panel:not([hidden]) { display: grid; gap: 2px; padding: 8px 0 12px; border-top: 1px solid var(--ew-line); }
  .ew-menu-panel a { padding: 10px 12px; border-radius: var(--ew-r-sm); color: var(--ew-ink); text-decoration: none; font-weight: 700; }
  .ew-menu-panel a[aria-current="page"] { background: var(--ew-blue-soft); color: var(--ew-link); }
}
@media (min-width: 761px) { .ew-menu-panel { display: none !important; } }
