/* ============================================================
   404x.io admin — design system
   Primitive → semantic → component tokens. Only semantic tokens
   are consumed by component styles.
   ============================================================ */

:root {
  color-scheme: light;

  /* Primitive palette */
  --green-50: #eef7f1;
  --green-100: #dff1e6;
  --green-200: #c3e6d0;
  --green-400: #37b67a;
  --green-500: #16935f;
  --green-600: #0b7a4d;
  --green-700: #08613d;
  --teal-400: #22b8a6;
  --ink-50: #f7f8f5;
  --ink-100: #eef0eb;
  --ink-200: #e2e6df;
  --ink-300: #cbd3ca;
  --ink-500: #6b7970;
  --ink-700: #33413a;
  --ink-900: #0d1511;

  /* Semantic: light */
  --bg-canvas: #f3f5f1;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-subtle: #eaeee7;
  --bg-inverse: #0d1511;
  --text-primary: #0d1511;
  --text-secondary: #33413a;
  --text-muted: #5f6d65;
  --text-inverse: #f2f7f3;
  --border-subtle: #e2e8df;
  --border-strong: #c9d3ca;
  --accent: #0b7a4d;
  --accent-hover: #08613d;
  --accent-2: #18a37a;
  --accent-soft: #e4f3ea;
  --accent-contrast: #ffffff;
  --btn-from: #0b7a4d;
  --btn-to: #0a6d48;
  --btn-text: #ffffff;
  --danger: #b23a44;
  --danger-soft: #fbecec;
  --danger-contrast: #ffffff;
  --warning: #a86a12;
  --warning-soft: #fdf3e2;
  --success: #0b7a4d;
  --focus-ring: rgba(11, 122, 77, 0.17);
  --grid-line: rgba(13, 21, 17, 0.045);
  --glass: rgba(255, 255, 255, 0.78);
  --code-bg: #0c1410;
  --code-text: #d9eadf;
  --tok-comment: #7f9387;
  --tok-operator: #b9c8be;
  --tok-number: #f0c674;
  --tok-string: #7fe0a6;
  --tok-keyword: #8bf0b6;
  --tok-function: #7fe3dd;
  --tok-attr: #f2a49d;
  --shadow-sm: 0 1px 2px rgba(13, 21, 17, 0.06);
  --shadow-md: 0 12px 28px -18px rgba(13, 21, 17, 0.28);
  --shadow-lg: 0 24px 60px -28px rgba(13, 21, 17, 0.32);
  --shadow-xl: 0 44px 110px -46px rgba(8, 20, 14, 0.38);

  /* Type, space, radius, motion */
  --font-sans: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: "JetBrains Mono Variable", "JetBrains Mono", ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
  --text-xs: 11px;
  --text-sm: 12.5px;
  --text-base: 15px;
  --text-md: 15.5px;
  --text-lg: 18px;
  --text-xl: 22px;
  --text-2xl: 28px;
  --text-3xl: clamp(30px, 4vw, 46px);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 48px;
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --duration-fast: 140ms;
  --duration-base: 220ms;
  --duration-slow: 420ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --sidebar-w: 272px;
  --sidebar-w-collapsed: 86px;
  --topbar-h: 78px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg-canvas: #070b08;
  --bg-surface: #0d1310;
  --bg-elevated: #121a15;
  --bg-subtle: #0a100c;
  --bg-inverse: #e8f1ea;
  --text-primary: #e8f1ea;
  --text-secondary: #b4c2b8;
  --text-muted: #8fa096;
  --text-inverse: #07100a;
  --border-subtle: #1b2720;
  --border-strong: #2b3a31;
  --accent: #48d99a;
  --accent-hover: #6ce6b0;
  --accent-2: #5eead4;
  --accent-soft: #10281c;
  --accent-contrast: #04140b;
  --btn-from: #48d99a;
  --btn-to: #2fc487;
  --btn-text: #04140b;
  --danger: #f08a92;
  --danger-soft: #2a1418;
  --danger-contrast: #2a1418;
  --warning: #e0b25c;
  --warning-soft: #2a2112;
  --success: #48d99a;
  --focus-ring: rgba(72, 217, 154, 0.2);
  --grid-line: rgba(232, 241, 234, 0.04);
  --glass: rgba(13, 19, 16, 0.72);
  --code-bg: #060a08;
  --code-text: #d9eadf;
  --tok-comment: #7f9387;
  --tok-operator: #b9c8be;
  --tok-number: #f0c674;
  --tok-string: #7fe0a6;
  --tok-keyword: #8bf0b6;
  --tok-function: #7fe3dd;
  --tok-attr: #f2a49d;
  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.02);
  --shadow-md: 0 14px 34px -22px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 28px 70px -30px rgba(0, 0, 0, 0.75);
  --shadow-xl: 0 50px 120px -48px rgba(0, 0, 0, 0.85);
}

/* ------------------------------------------------------------
   Reset and base
   ------------------------------------------------------------ */
*,
*::before,
*::after { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select { font: inherit; color: inherit; }

button { cursor: pointer; }

a { color: inherit; text-decoration: none; }

img,
svg { display: block; }

[hidden] { display: none !important; }

::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

h1, h2, h3, h4, p { margin-top: 0; }

.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;
}

.btn svg,
.icon-btn svg,
.nav-icon svg,
.menu-icon svg,
.stat-icon svg,
.topbar-link svg,
.sidebar-site-link svg,
.sidebar-logout svg,
.search-field svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------
   Buttons, inputs, feedback primitives
   ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  transition:
    transform var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-base) var(--ease-out);
}

.btn svg { width: 16px; height: 16px; }

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: wait; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--btn-from), var(--btn-to));
  color: var(--btn-text);
  box-shadow: 0 10px 24px -14px color-mix(in srgb, var(--accent) 65%, transparent);
}

.btn-primary:hover {
  box-shadow: 0 16px 32px -16px color-mix(in srgb, var(--accent) 70%, transparent);
  filter: saturate(1.06);
}

.btn-ghost {
  border-color: var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
}

.btn-ghost:hover {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.btn-danger { background: var(--danger); color: var(--danger-contrast); }
.btn-danger:hover { filter: brightness(1.05); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-muted);
  transition: color var(--duration-fast), border-color var(--duration-fast), background-color var(--duration-fast);
}

.icon-btn:hover { border-color: var(--border-strong); background: var(--bg-subtle); color: var(--text-primary); }

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}

input { height: 40px; padding: 0 var(--space-3); }
textarea { padding: var(--space-3); resize: vertical; }

input::placeholder,
textarea::placeholder { color: color-mix(in srgb, var(--text-muted) 72%, transparent); }

input:hover,
textarea:hover { border-color: var(--border-strong); }

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--focus-ring);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: var(--space-4);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 600;
}

.form-error {
  margin: 0 0 var(--space-3);
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 24%, var(--border-subtle));
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--text-sm);
}

.form-hint {
  margin: var(--space-2) 0 var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: 1.6;
}

.optional { color: var(--text-muted); font-weight: 400; }
.muted { color: var(--text-muted); }

.eyebrow {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 14%, transparent);
  flex: none;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 currentColor;
  animation: pulse 2.4s var(--ease-out) infinite;
}

/* ------------------------------------------------------------
   Login — centered glass card over an animated field
   ------------------------------------------------------------ */
.login-view {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding: clamp(24px, 5vw, 64px);
  overflow: hidden;
  color-scheme: dark;
  --bg-canvas: #040806;
  --bg-surface: #08110b;
  --bg-elevated: #0b160f;
  --bg-subtle: #06100a;
  --text-primary: #e7f6ec;
  --text-secondary: #aac2b3;
  --text-muted: #7f9a88;
  --border-subtle: rgba(96, 220, 150, 0.14);
  --border-strong: rgba(96, 220, 150, 0.3);
  --accent: #48d99a;
  --accent-hover: #6ce6b0;
  --accent-2: #5eead4;
  --accent-soft: rgba(72, 217, 154, 0.1);
  --accent-contrast: #04140b;
  --btn-from: #48d99a;
  --btn-to: #2fc487;
  --btn-text: #04140b;
  --focus-ring: rgba(72, 217, 154, 0.2);
  --grid-line: rgba(72, 217, 154, 0.07);
  background:
    radial-gradient(110% 80% at 50% -10%, rgba(30, 120, 80, 0.26), transparent 60%),
    #040806;
  color: var(--text-primary);
}

.login-view::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(4, 8, 6, 0.15), transparent 20%, transparent 78%, rgba(4, 8, 6, 0.55)),
    radial-gradient(ellipse at center, transparent 32%, rgba(4, 8, 6, 0.5) 100%);
}

.login-ambient {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.ambient-orb {
  position: absolute;
  width: 52vmax;
  height: 52vmax;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.42;
  will-change: transform;
}

.ambient-orb--a {
  top: -26vmax;
  left: -16vmax;
  background: color-mix(in srgb, var(--accent) 42%, transparent);
  animation: drift-a 26s var(--ease-in-out) infinite alternate;
}

.ambient-orb--b {
  right: -22vmax;
  bottom: -30vmax;
  background: color-mix(in srgb, var(--accent-2) 34%, transparent);
  animation: drift-b 32s var(--ease-in-out) infinite alternate;
}

.ambient-orb--c {
  top: 26%;
  left: 58%;
  width: 30vmax;
  height: 30vmax;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  animation: drift-a 22s var(--ease-in-out) 2s infinite alternate-reverse;
}

html[data-theme="dark"] .ambient-orb { opacity: 0.3; }

.ambient-grid {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse at center, #000 0%, transparent 72%);
  opacity: 0.55;
}

.login-rain {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  opacity: 0.52;
  pointer-events: none;
}

.login-controls {
  position: fixed;
  top: var(--space-5);
  right: var(--space-5);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.lang-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  transition: color var(--duration-fast), border-color var(--duration-fast), background-color var(--duration-fast);
}

.lang-toggle:hover { border-color: var(--border-strong); background: var(--bg-subtle); color: var(--text-primary); }

.login-shell {
  position: relative;
  z-index: 3;
  display: grid;
  justify-items: center;
  gap: var(--space-4);
  width: min(100%, 344px);
  animation: rise var(--duration-slow) var(--ease-out) both;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #063d27));
  color: #fff;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 10px 24px -14px color-mix(in srgb, var(--accent) 70%, transparent);
}

.brand-mark--lg {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  font-size: 22px;
}

.login-brand-copy { display: grid; gap: 1px; }
.login-brand-copy strong { font-size: var(--text-md); font-weight: 700; letter-spacing: -0.02em; }
.login-brand-copy small {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.login-card {
  position: relative;
  width: 100%;
  padding: clamp(24px, 4vw, 32px);
  overflow: hidden;
  border: 1px solid rgba(96, 220, 150, 0.2);
  border-radius: 22px;
  background: linear-gradient(160deg, rgba(10, 22, 15, 0.92), rgba(5, 12, 8, 0.86));
  box-shadow:
    0 40px 100px -40px rgba(0, 0, 0, 0.9),
    0 0 0 1px rgba(72, 217, 154, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  text-align: center;
  -webkit-backdrop-filter: blur(20px) saturate(120%);
  backdrop-filter: blur(20px) saturate(120%);
}

.login-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 75% at 50% 0%, var(--accent-soft), transparent 62%);
  opacity: 0.85;
  pointer-events: none;
}

.login-card > * { position: relative; }

.login-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--border-subtle));
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-surface) 70%, transparent);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.login-card h1 {
  margin: var(--space-4) 0 var(--space-2);
  font-size: clamp(24px, 4.4vw, 30px);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.1;
}

.login-sub {
  max-width: 32ch;
  margin: 0 auto var(--space-5);
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 1.7;
}

.login-card form { width: min(100%, 184px); margin-inline: auto; text-align: left; }
.login-card .field { margin-bottom: var(--space-4); }
.login-card input { height: 40px; border-radius: var(--radius-sm); }

.btn-login {
  display: flex;
  width: fit-content;
  min-width: 148px;
  min-height: 40px;
  margin: var(--space-2) auto 0;
  padding: 0 16px;
  justify-content: center;
  gap: 10px;
  font-size: 13px;
}

.login-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.login-meta span { display: inline-flex; align-items: center; gap: 7px; }

.login-foot {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-foot span { margin: 0 3px; opacity: 0.55; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: var(--text-xs);
  transition: color var(--duration-fast), border-color var(--duration-fast), background-color var(--duration-fast);
}

.theme-toggle:hover { border-color: var(--border-strong); background: var(--bg-subtle); color: var(--text-primary); }
.theme-toggle [data-theme-icon] { font-size: 14px; line-height: 1; }

/* ------------------------------------------------------------
   Shell / sidebar
   ------------------------------------------------------------ */
.admin-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.admin-app.is-sidebar-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  height: 100vh;
  padding: var(--space-5) var(--space-4);
  overflow: hidden auto;
  border-right: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--bg-surface) 86%, var(--bg-canvas));
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 220px;
  background: radial-gradient(120% 85% at 18% 0%, var(--accent-soft), transparent 72%);
  pointer-events: none;
  opacity: 0.8;
}

.sidebar > * { position: relative; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 2px var(--space-2) var(--space-2);
}

.brand-text { display: grid; gap: 1px; min-width: 0; }
.brand-text strong { font-size: var(--text-base); font-weight: 700; letter-spacing: -0.02em; }
.brand-text small {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.sidebar-nav { display: grid; gap: var(--space-5); align-content: start; }

.nav-group { display: grid; gap: var(--space-2); }

.nav-group-title {
  margin: 0;
  padding-inline: var(--space-2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.nav-group-items { display: grid; gap: 3px; }

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 40px;
  padding: 9px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 550;
  transition: color var(--duration-fast), background-color var(--duration-fast), transform var(--duration-fast) var(--ease-out);
}

.nav-item:hover { background: var(--bg-subtle); color: var(--text-primary); transform: translateX(2px); }

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.nav-item.is-active::before {
  content: "";
  position: absolute;
  inset-block: 9px;
  left: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  flex: none;
  color: var(--text-muted);
  transition: color var(--duration-fast);
}

.nav-icon svg { width: 18px; height: 18px; }
.nav-icon--github svg { width: 17px; height: 17px; }
.nav-item:hover .nav-icon { color: var(--text-primary); }
.nav-item.is-active .nav-icon { color: var(--accent); }

.nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-foot {
  display: grid;
  gap: 2px;
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

.sidebar-site-link,
.sidebar-logout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: 38px;
  padding: 8px var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  text-align: left;
  transition: color var(--duration-fast), background-color var(--duration-fast);
}

.sidebar-site-link svg,
.sidebar-logout svg { width: 15px; height: 15px; flex: none; }
.sidebar-site-link:hover { background: var(--bg-subtle); color: var(--text-primary); }
.sidebar-logout:hover { background: var(--danger-soft); color: var(--danger); }

/* Collapsed rail */
.is-sidebar-collapsed .sidebar { padding-inline: var(--space-3); }
.is-sidebar-collapsed .sidebar-brand { justify-content: center; padding-inline: 0; }
.is-sidebar-collapsed .brand-text,
.is-sidebar-collapsed .nav-group-title,
.is-sidebar-collapsed .nav-label,
.is-sidebar-collapsed .sidebar-site-link span,
.is-sidebar-collapsed .sidebar-logout span {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.is-sidebar-collapsed .nav-group { gap: 0; }
.is-sidebar-collapsed .nav-item { justify-content: center; gap: 0; padding: 11px 0; }
.is-sidebar-collapsed .nav-item:hover { transform: none; }
.is-sidebar-collapsed .nav-item.is-active::before { inset-block: 12px; }
.is-sidebar-collapsed .sidebar-site-link,
.is-sidebar-collapsed .sidebar-logout { justify-content: center; padding-inline: 0; }

/* ------------------------------------------------------------
   Topbar
   ------------------------------------------------------------ */
.admin-shell { min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--topbar-h);
  padding: 12px clamp(20px, 3vw, 42px);
  border-bottom: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--bg-canvas) 82%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
}

.menu-button { display: none; }

.sidebar-collapse {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: none;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-xs);
  transition: color var(--duration-fast), border-color var(--duration-fast), background-color var(--duration-fast);
}

.sidebar-collapse:hover { border-color: var(--border-strong); background: var(--bg-subtle); color: var(--text-primary); }
.collapse-glyph { display: block; font-size: 15px; line-height: 1; }
.collapse-label { font-weight: 550; }

.topbar-title { flex: 1; min-width: 0; }
.topbar-kicker {
  display: block;
  margin-bottom: 2px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.topbar-title h1 {
  margin: 0;
  overflow: hidden;
  font-size: 18px;
  font-weight: 660;
  letter-spacing: -0.025em;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: var(--space-2); }

.topbar-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 550;
  transition: color var(--duration-fast), background-color var(--duration-fast);
}

.topbar-link svg { width: 14px; height: 14px; }
.topbar-link:hover { background: var(--bg-subtle); color: var(--text-primary); }

.topbar-user {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 11px 4px 4px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

/* ------------------------------------------------------------
   Main / page transitions
   ------------------------------------------------------------ */
.admin-main {
  width: min(1440px, 100%);
  margin-inline: auto;
  padding: clamp(24px, 3.4vw, 44px);
}

.view { animation: view-in var(--duration-slow) var(--ease-out) both; }

/* ------------------------------------------------------------
   Dashboard
   ------------------------------------------------------------ */
.dashboard-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: clamp(20px, 4vw, 44px);
  align-items: center;
  margin-bottom: clamp(24px, 4vw, 44px);
  padding: clamp(26px, 4vw, 48px);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--bg-surface) 92%, transparent), color-mix(in srgb, var(--accent-soft) 62%, var(--bg-surface)));
  box-shadow: var(--shadow-md);
}

.dashboard-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at 18% 20%, #000 0%, transparent 70%);
  pointer-events: none;
}

.dashboard-hero::after {
  content: "";
  position: absolute;
  top: -40%;
  right: -12%;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 18%, transparent), transparent 66%);
  pointer-events: none;
}

.hero-copy { position: relative; z-index: 1; }

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px;
  border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--border-subtle));
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-surface) 66%, transparent);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hero-copy h2 {
  margin: var(--space-5) 0 var(--space-3);
  font-size: var(--text-3xl);
  font-weight: 720;
  letter-spacing: -0.055em;
  line-height: 1.06;
}

.hero-copy h2 em {
  font-style: normal;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-copy p {
  max-width: 42ch;
  margin: 0 0 var(--space-6);
  color: var(--text-muted);
  font-size: var(--text-base);
  line-height: 1.7;
}

.hero-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

.hero-visual {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 270px;
  isolation: isolate;
}

.hero-ring {
  position: absolute;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: 50%;
}

.hero-ring--one { width: 180px; height: 180px; animation: rotate 28s linear infinite; border-style: dashed; }
.hero-ring--two { width: 260px; height: 260px; opacity: 0.6; animation: rotate 44s linear infinite reverse; }
.hero-ring--three { width: 330px; height: 330px; opacity: 0.32; }

.hero-core {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  border-radius: 26px;
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 45%, #063d27));
  color: #fff;
  font-family: var(--font-mono);
  font-size: 34px;
  font-weight: 700;
  box-shadow:
    0 24px 50px -22px color-mix(in srgb, var(--accent) 75%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.hero-chip {
  position: absolute;
  padding: 6px 11px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-surface) 86%, transparent);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: float 7s var(--ease-in-out) infinite;
}

.hero-chip--markdown { top: 16%; left: 10%; }
.hero-chip--github { top: 30%; right: 4%; animation-delay: -2.4s; }
.hero-chip--deploy { bottom: 16%; left: 22%; animation-delay: -4.8s; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
  margin-bottom: clamp(28px, 4vw, 48px);
}

.stat-card {
  position: relative;
  padding: var(--space-5);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-base) var(--ease-out), border-color var(--duration-fast), box-shadow var(--duration-base) var(--ease-out);
}

.stat-card:hover { transform: translateY(-3px); border-color: var(--border-strong); box-shadow: var(--shadow-md); }

.stat-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-bottom: var(--space-5);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
}

.stat-icon svg { width: 18px; height: 18px; }

.stat-label {
  display: block;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  margin: 5px 0 var(--space-3);
  overflow: hidden;
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-card a {
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
}

.stat-card a span { transition: transform var(--duration-fast) var(--ease-out); display: inline-block; }
.stat-card a:hover span { transform: translateX(3px); }

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.section-heading h2 {
  margin: 4px 0 0;
  font-size: clamp(20px, 2vw, 24px);
  font-weight: 680;
  letter-spacing: -0.035em;
}

.section-heading > p {
  max-width: 430px;
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 1.65;
}

.section-heading--compact { margin-bottom: var(--space-3); }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  margin-bottom: clamp(28px, 4vw, 44px);
}

.menu-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 196px;
  padding: var(--space-6);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-base) var(--ease-out), border-color var(--duration-fast), box-shadow var(--duration-base) var(--ease-out);
}

.menu-card::after {
  content: "";
  position: absolute;
  right: -60px;
  bottom: -70px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-soft), transparent 70%);
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-out);
  pointer-events: none;
}

.menu-card:hover { transform: translateY(-4px); border-color: color-mix(in srgb, var(--accent) 24%, var(--border-subtle)); box-shadow: var(--shadow-lg); }
.menu-card:hover::after { opacity: 1; }

.menu-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--space-5);
  border: 1px solid color-mix(in srgb, var(--accent) 14%, var(--border-subtle));
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent);
}

.menu-icon svg { width: 20px; height: 20px; }
.menu-icon--github svg { width: 19px; height: 19px; }

.menu-index {
  position: absolute;
  top: var(--space-5);
  right: var(--space-5);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.menu-card h3 { margin: 0 0 5px; font-size: var(--text-lg); font-weight: 680; letter-spacing: -0.025em; }
.menu-card p { max-width: 34ch; margin: 0; color: var(--text-muted); font-size: var(--text-sm); line-height: 1.65; }

.menu-arrow {
  margin-top: auto;
  align-self: flex-end;
  color: var(--text-muted);
  font-size: 16px;
  transition: transform var(--duration-fast) var(--ease-out), color var(--duration-fast);
}

.menu-card:hover .menu-arrow { color: var(--accent); transform: translate(2px, -2px); }

.github-warning {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
  padding: 12px var(--space-4);
  border: 1px solid color-mix(in srgb, var(--danger) 26%, var(--border-subtle));
  border-radius: var(--radius-md);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--text-sm);
}

.github-warning a { margin-left: auto; font-weight: 650; }

.recent-card {
  padding: clamp(20px, 3vw, 28px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.recent-list { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; }

.recent-item {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 13px var(--space-2);
  border-top: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  transition: color var(--duration-fast), background-color var(--duration-fast), transform var(--duration-fast) var(--ease-out);
}

.recent-item:hover { background: var(--bg-subtle); color: var(--accent); transform: translateX(4px); }
.recent-item span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item span:last-child { flex: none; color: var(--text-muted); font-size: 10px; }

/* ------------------------------------------------------------
   View headers / shared content blocks
   ------------------------------------------------------------ */
.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}

.view-head h2 {
  margin: 0;
  font-size: clamp(26px, 3vw, 34px);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.1;
}

.view-desc {
  max-width: 62ch;
  margin: var(--space-2) 0 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 1.65;
}

.view-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

.notice {
  margin: 0 0 var(--space-5);
  padding: 12px var(--space-4);
  border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--border-subtle));
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.65;
}

.notice code,
.settings-footnote code,
.settings-intro code {
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  background: color-mix(in srgb, var(--bg-surface) 78%, transparent);
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.empty-hint {
  margin: 0;
  padding: var(--space-6);
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

.text-link { color: var(--accent); font-size: var(--text-xs); font-weight: 650; }
.text-link:hover { text-decoration: underline; text-underline-offset: 3px; }

.back-link {
  display: inline-flex;
  align-items: center;
  margin-bottom: var(--space-3);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-xs);
  transition: color var(--duration-fast), transform var(--duration-fast) var(--ease-out);
}

.back-link:hover { color: var(--accent); transform: translateX(-2px); }

.save-state { color: var(--text-muted); font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.04em; }

/* ------------------------------------------------------------
   Posts table
   ------------------------------------------------------------ */
.search-field { position: relative; display: flex; align-items: center; }
.search-field svg {
  position: absolute;
  left: 12px;
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: min(240px, 34vw);
  height: 38px;
  padding-left: 35px;
  background: var(--bg-surface);
}

.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
  padding: 10px var(--space-4);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--border-subtle));
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-sm);
  animation: view-in var(--duration-base) var(--ease-out) both;
}

.bulk-actions { display: flex; gap: var(--space-2); }
.bulk-bar .btn { min-height: 34px; }

.posts-table-wrap {
  overflow: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.posts-table { width: 100%; border-collapse: collapse; table-layout: fixed; }

.posts-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 12px var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--bg-surface) 92%, var(--bg-subtle));
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-align: left;
  text-transform: uppercase;
}

.posts-table td {
  padding: 12px var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  vertical-align: middle;
}

.posts-table tr:last-child td { border-bottom: 0; }
.posts-table tbody tr { cursor: pointer; transition: background-color var(--duration-fast); }
.posts-table tbody tr:hover { background: var(--bg-subtle); }
.posts-table tbody tr.is-selected { background: var(--accent-soft); }

.col-check { width: 44px; }
.col-size { width: 100px; }
.col-actions { width: 150px; }
.col-mark { width: 38px; }

.posts-table input[type="checkbox"] {
  width: 15px;
  height: 15px;
  padding: 0;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.row-name {
  display: block;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.row-actions { display: flex; gap: 6px; }

.row-button {
  padding: 4px 9px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 550;
  transition: color var(--duration-fast), border-color var(--duration-fast), background-color var(--duration-fast);
}

.row-button:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.row-button--danger:hover { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }

.row-mark { color: var(--accent); font-weight: 700; opacity: 0; }
tr.is-selected .row-mark { opacity: 1; }

.table-foot { margin: var(--space-3) 2px 0; color: var(--text-muted); font-family: var(--font-mono); font-size: 10px; text-align: right; }

.table-loading { padding: 34px 18px !important; color: var(--text-muted); font-size: var(--text-sm); text-align: center; }
.table-loading::before {
  content: "";
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 8px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  vertical-align: -2px;
  animation: rotate 0.8s linear infinite;
}
.table-loading--error { color: var(--danger); }
.table-loading--error::before { display: none; }

/* ------------------------------------------------------------
   Editor
   ------------------------------------------------------------ */
.editor-view-head { align-items: flex-start; }

.editor-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.editor-file-row { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }

.inline-field {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.inline-field input {
  width: 320px;
  max-width: 100%;
  height: 36px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.inline-check input {
  width: 15px;
  height: 15px;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.editor-tip { color: var(--text-muted); font-size: var(--text-xs); }

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: wrap;
  padding: 7px;
  border: 1px solid var(--border-subtle);
  border-bottom: 0;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: color-mix(in srgb, var(--bg-surface) 88%, var(--bg-subtle));
}

.editor-toolbar button {
  min-width: 31px;
  height: 31px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 650;
  transition: color var(--duration-fast), background-color var(--duration-fast);
}

.editor-toolbar button:hover { background: var(--bg-subtle); color: var(--accent); }
.toolbar-sep { width: 1px; height: 18px; margin: 0 5px; background: var(--border-subtle); }

.editor-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 600px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  background: var(--bg-surface);
}

.editor-pane { min-width: 0; border-right: 1px solid var(--border-subtle); }

#post-content {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 600px;
  padding: var(--space-5);
  border: 0;
  border-radius: 0;
  resize: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.8;
  outline: none;
}

#post-content:focus { box-shadow: none; }

.preview-pane { min-width: 0; overflow: auto; background: var(--bg-subtle); }
.preview-meta { display: flex; flex-wrap: wrap; gap: 6px; padding: 14px var(--space-5) 0; }
.preview-meta:empty { display: none; }

.meta-chip {
  padding: 3px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 9.5px;
}

.markdown-preview { padding: 18px 22px 30px; color: var(--text-primary); font-size: 13.5px; line-height: 1.78; }
.markdown-preview > :first-child { margin-top: 0; }
.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4 { margin: 1.5em 0 0.6em; line-height: 1.3; letter-spacing: -0.02em; }
.markdown-preview h1 { font-size: 1.8em; }
.markdown-preview h2 { font-size: 1.45em; }
.markdown-preview h3 { font-size: 1.18em; }
.markdown-preview p { margin: 0 0 1em; }
.markdown-preview a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.markdown-preview ul,
.markdown-preview ol { padding-left: 1.4em; }
.markdown-preview li::marker { color: var(--accent); }
.markdown-preview blockquote {
  margin: 1em 0;
  padding: 0.2em 0 0.2em 1em;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}
.markdown-preview code {
  padding: 0.15em 0.4em;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  font-family: var(--font-mono);
  font-size: 0.88em;
}
.markdown-preview pre {
  overflow: auto;
  padding: 15px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--code-text);
}
.markdown-preview pre code { padding: 0; border: 0; background: transparent; color: var(--code-text); }
.markdown-preview img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }
.markdown-preview table { width: 100%; border-collapse: collapse; font-size: 0.92em; }
.markdown-preview th,
.markdown-preview td { padding: 7px 9px; border: 1px solid var(--border-subtle); text-align: left; }
.markdown-preview hr { margin: 1.5em 0; border: 0; border-top: 1px solid var(--border-subtle); }
.markdown-preview .preview-error {
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 24%, var(--border-subtle));
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--text-sm);
}

.markdown-preview .mermaid {
  margin: 1.2em 0;
  padding: 14px;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  text-align: center;
}
.markdown-preview .mermaid svg { max-width: 100%; height: auto; }

.editor-status {
  display: flex;
  gap: 18px;
  padding: 9px 3px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
}
.editor-status span:last-child { margin-left: auto; }

.editor-split.preview-only { grid-template-columns: minmax(0, 1fr); }
.editor-split.preview-only .editor-pane { display: none; }

/* ------------------------------------------------------------
   Settings / site / GitHub
   ------------------------------------------------------------ */
.settings-card {
  width: 100%;
  max-width: 620px;
  padding: clamp(22px, 3vw, 30px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.settings-card form { max-width: 430px; }
.settings-intro { margin: 0 0 var(--space-5); color: var(--text-muted); font-size: var(--text-sm); line-height: 1.75; }

.inline-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.connection-status {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding: var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
}

.connection-status strong { display: block; font-size: var(--text-sm); font-weight: 650; }
.connection-status span:last-child { display: block; margin-top: 2px; color: var(--text-muted); font-size: var(--text-xs); }
.connection-status .status-dot { margin-top: 5px; }
.connection-status.is-disconnected .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 14%, transparent);
}

.github-oauth {
  margin-bottom: var(--space-5);
  padding: var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
}

.github-oauth .btn { width: 100%; }
.github-oauth .form-hint { margin: var(--space-3) 0 0; }
.github-oauth code,
.github-note code {
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  font-family: var(--font-mono);
}

.github-note { margin: var(--space-3) 0 0; color: var(--danger); font-size: var(--text-xs); line-height: 1.6; }

.token-fallback { margin-bottom: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--border-subtle); }
.token-fallback summary {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}
.token-fallback summary::-webkit-details-marker { display: none; }
.token-fallback summary::before { content: "+ "; color: var(--accent); font-weight: 700; }
.token-fallback[open] summary::before { content: "− "; }
.token-fallback[open] summary { margin-bottom: var(--space-4); color: var(--text-primary); }
.token-fallback .form-hint { margin: 6px 0 var(--space-4); }

.github-actions { padding-top: var(--space-1); }

.site-settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--space-4);
  align-items: start;
}

.site-menu-card,
.site-features-card { max-width: none; }

.site-menu-card h3,
.site-features-card h3 { margin: 0; font-size: var(--text-md); font-weight: 680; letter-spacing: -0.02em; }

.site-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); }
.site-card-head p,
.site-features-card > p { margin: 5px 0 0; color: var(--text-muted); font-size: var(--text-xs); line-height: 1.65; }

.menu-editor { display: grid; gap: var(--space-3); }

.menu-node {
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
}

.menu-node-head {
  display: grid;
  grid-template-columns: 28px minmax(100px, 1fr) minmax(100px, 1fr) minmax(130px, 1.2fr) 110px auto;
  gap: var(--space-2);
  align-items: end;
  padding: var(--space-3);
}

.menu-order { align-self: center; color: var(--text-muted); font-family: var(--font-mono); font-size: 10px; }

.menu-field {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
}

.menu-field input,
.menu-field select {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: var(--text-xs);
  font-weight: 400;
}

.menu-row-actions { display: flex; align-items: center; gap: 3px; padding-bottom: 1px; }

.menu-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 12px;
  transition: color var(--duration-fast), border-color var(--duration-fast), background-color var(--duration-fast);
}

.menu-icon-btn:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.menu-icon-btn--danger:hover { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }

.menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 10.5px;
  white-space: nowrap;
}

.menu-toggle input { width: 12px; height: 12px; padding: 0; margin: 0; accent-color: var(--accent); }

.menu-children { display: grid; gap: 6px; padding: 0 var(--space-3) var(--space-3) 44px; }

.menu-child {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(90px, 1fr) minmax(120px, 1.2fr) 100px auto;
  gap: var(--space-2);
  align-items: end;
  padding: var(--space-2);
  border-left: 2px solid var(--border-subtle);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  background: var(--bg-surface);
}

.menu-add-child {
  justify-self: start;
  margin-top: 2px;
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 650;
}

.feature-list { display: grid; gap: 0; margin: var(--space-5) 0; }

.feature-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 12px 0;
  border-top: 1px solid var(--border-subtle);
  cursor: pointer;
}

.feature-row:last-child { border-bottom: 1px solid var(--border-subtle); }
.feature-row strong { display: block; font-size: var(--text-sm); font-weight: 600; }
.feature-row small { display: block; margin-top: 2px; color: var(--text-muted); font-size: 10.5px; }

.feature-row input[type="checkbox"] {
  position: relative;
  width: 38px;
  height: 22px;
  flex: none;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-subtle);
  appearance: none;
  cursor: pointer;
  transition: background-color var(--duration-fast), border-color var(--duration-fast);
}

.feature-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-fast) var(--ease-out);
}

.feature-row input[type="checkbox"]:checked { border-color: var(--accent); background: var(--accent); }
.feature-row input[type="checkbox"]:checked::after { transform: translateX(16px); background: var(--accent-contrast); }

.settings-footnote { margin: var(--space-5) 0 0; color: var(--text-muted); font-size: var(--text-xs); }

/* ------------------------------------------------------------
   Toast / skip link / focus
   ------------------------------------------------------------ */
.toast {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 100;
  max-width: min(390px, calc(100vw - 40px));
  padding: 12px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  animation: toast-in var(--duration-base) var(--ease-out) both;
}

.toast.is-error { border-color: color-mix(in srgb, var(--danger) 36%, var(--border-subtle)); color: var(--danger); }

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 200;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: var(--text-sm);
  transform: translateY(-160%);
  transition: transform var(--duration-fast) var(--ease-out);
}

.skip-link:focus { transform: none; }

:where(a, button, input, textarea, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible { outline: none; }

.posts-table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#post-content:focus-visible { outline-offset: -2px; }

/* ------------------------------------------------------------
   Markdown code tokens (Prism)
   ------------------------------------------------------------ */
.markdown-preview .token.comment,
.markdown-preview .token.prolog,
.markdown-preview .token.doctype,
.markdown-preview .token.cdata { color: var(--tok-comment, #7f8f84); font-style: italic; }
.markdown-preview .token.punctuation { color: var(--tok-operator, #b8c4bb); }
.markdown-preview .token.property,
.markdown-preview .token.tag,
.markdown-preview .token.boolean,
.markdown-preview .token.number,
.markdown-preview .token.constant,
.markdown-preview .token.symbol { color: var(--tok-number, #e7c476); }
.markdown-preview .token.selector,
.markdown-preview .token.attr-name,
.markdown-preview .token.string,
.markdown-preview .token.char,
.markdown-preview .token.builtin { color: var(--tok-string, #a8d9a0); }
.markdown-preview .token.operator,
.markdown-preview .token.entity,
.markdown-preview .token.url { color: var(--tok-operator, #b8c4bb); }
.markdown-preview .token.atrule,
.markdown-preview .token.attr-value,
.markdown-preview .token.keyword { color: var(--tok-keyword, #8fd7b0); font-weight: 600; }
.markdown-preview .token.function,
.markdown-preview .token.class-name { color: var(--tok-function, #8fd3d0); }
.markdown-preview .token.regex,
.markdown-preview .token.important,
.markdown-preview .token.variable { color: var(--tok-attr, #e2a19a); }
.markdown-preview .token.italic { font-style: italic; }
.markdown-preview .token.bold { font-weight: 700; }

/* ------------------------------------------------------------
   Responsive
   ------------------------------------------------------------ */
@media (max-width: 1180px) {
  .dashboard-hero { grid-template-columns: minmax(0, 1fr) 300px; }
  .hero-ring--three { width: 280px; height: 280px; }
  .site-settings-grid { grid-template-columns: 1fr; }
  .site-features-card { max-width: 700px; }
}

@media (max-width: 1100px) {
  .dashboard-hero { grid-template-columns: 1fr; }
  .hero-visual { display: none; }
}

@media (max-width: 980px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid .stat-card:last-child { grid-column: 1 / -1; }
  .editor-split { grid-template-columns: 1fr; }
  .editor-pane { border-right: 0; border-bottom: 1px solid var(--border-subtle); }
  #post-content { min-height: 430px; }
  .preview-pane { max-height: 540px; }
}

@media (max-width: 760px) {
  :root { --topbar-h: 64px; }

  .admin-app,
  .admin-app.is-sidebar-collapsed { display: block; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: min(300px, 86vw);
    height: 100vh;
    transform: translateX(-102%);
    transition: transform var(--duration-base) var(--ease-out);
    box-shadow: var(--shadow-xl);
  }

  .admin-app.menu-open .sidebar { transform: none; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 55; background: rgba(4, 10, 6, 0.5); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }

  .menu-button { display: inline-flex; }
  .sidebar-collapse { display: none; }

  .is-sidebar-collapsed .sidebar { width: min(300px, 86vw); padding: var(--space-5) var(--space-4); }
  .is-sidebar-collapsed .sidebar-brand { justify-content: flex-start; padding-inline: var(--space-2); }
  .is-sidebar-collapsed .brand-text,
  .is-sidebar-collapsed .nav-group-title,
  .is-sidebar-collapsed .nav-label,
  .is-sidebar-collapsed .sidebar-site-link span,
  .is-sidebar-collapsed .sidebar-logout span {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }
  .is-sidebar-collapsed .nav-item { justify-content: flex-start; gap: var(--space-3); padding: 9px var(--space-3); }
  .is-sidebar-collapsed .sidebar-site-link,
  .is-sidebar-collapsed .sidebar-logout { justify-content: space-between; padding-inline: var(--space-3); }

  .topbar { padding: 10px var(--space-4); }
  .topbar-kicker { display: none; }
  .topbar-title h1 { font-size: 20px; }
  .topbar-link span { display: none; }
  .topbar-link { width: 34px; padding: 0; justify-content: center; }
  .topbar-user span:last-child { display: none; }
  .topbar-user { padding: 4px; border: 0; background: transparent; }

  .admin-main { padding: var(--space-5) var(--space-4) var(--space-8); }

  .stats-grid,
  .menu-grid { grid-template-columns: 1fr; }
  .stats-grid .stat-card:last-child { grid-column: auto; }
  .menu-card { min-height: 158px; padding: var(--space-5); }
  .menu-icon { margin-bottom: var(--space-4); }

  .section-heading { align-items: flex-start; flex-direction: column; gap: var(--space-2); }
  .view-head { align-items: flex-start; flex-direction: column; }
  .view-actions { width: 100%; }
  .search-field { flex: 1; }
  .search-input { width: 100%; }

  .dashboard-hero { padding: var(--space-6); border-radius: var(--radius-lg); }
  .hero-copy h2 { font-size: clamp(27px, 8vw, 36px); }

  .editor-toolbar { overflow-x: auto; flex-wrap: nowrap; }
  .editor-toolbar button { flex: none; }
  .editor-tip { display: none; }
  .inline-field { width: 100%; }
  .inline-field input { width: 100%; }
  #post-content { min-height: 360px; height: 42vh; }
  .preview-pane { max-height: none; }

  .posts-table .col-size { display: none; }
  .posts-table th:nth-child(3),
  .posts-table td:nth-child(3) { display: none; }
  .col-actions { width: 118px; }
  .row-button { padding: 3px 6px; }

  .menu-node-head { grid-template-columns: 1fr 1fr; align-items: start; }
  .menu-order { grid-column: 1 / -1; }
  .menu-node-head .menu-field:nth-of-type(3),
  .menu-node-head .menu-field:nth-of-type(4),
  .menu-row-actions { grid-column: 1 / -1; }
  .menu-row-actions { flex-wrap: wrap; }
  .menu-child { grid-template-columns: 1fr 1fr; }
  .menu-child .menu-field:nth-of-type(3),
  .menu-child .menu-field:nth-of-type(4),
  .menu-child .menu-row-actions { grid-column: 1 / -1; }
  .menu-children { padding-left: 18px; }

  .login-view { padding: var(--space-5) var(--space-4); }
  .login-card { border-radius: var(--radius-lg); }
  .login-controls { top: var(--space-3); right: var(--space-3); }
}

@media (max-width: 460px) {
  .topbar-actions .theme-toggle { width: 34px; padding: 0; justify-content: center; }
  .topbar-actions .theme-toggle [data-theme-label] { display: none; }
  .hero-actions .btn { flex: 1; }
}

@media (pointer: coarse) {
  .menu-button,
  .theme-toggle { min-width: 44px; min-height: 44px; }
  .nav-item { min-height: 44px; }
  .row-button { min-height: 36px; padding: 7px 10px; }
  .btn { min-height: 44px; }
}

/* ------------------------------------------------------------
   Motion
   ------------------------------------------------------------ */
@keyframes view-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(18px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes rotate {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 currentColor; }
  50% { opacity: 0.65; box-shadow: 0 0 0 5px transparent; }
}

@keyframes drift-a {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(6vw, 4vh, 0) scale(1.08); }
}

@keyframes drift-b {
  from { transform: translate3d(0, 0, 0) scale(1.05); }
  to { transform: translate3d(-7vw, -5vh, 0) scale(0.95); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .admin-app { transition: none; }
}

/* ------------------------------------------------------------
   AI providers and writing assistant
   Semantic tokens only; no raw component colours.
   ------------------------------------------------------------ */
.ai-status {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 650;
  white-space: nowrap;
}

.ai-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.ai-status.is-on {
  border-color: color-mix(in srgb, var(--accent) 32%, var(--border-subtle));
  background: var(--accent-soft);
  color: var(--accent);
}

.ai-status.is-on::before {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 16%, transparent);
}

.ai-status.is-warn {
  border-color: color-mix(in srgb, var(--warning) 32%, var(--border-subtle));
  background: var(--warning-soft);
  color: var(--warning);
}

.ai-status.is-warn::before {
  background: var(--warning);
}

.ai-config-card {
  width: 100%;
  max-width: none;
  margin-bottom: var(--space-5);
}

.ai-config-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.ai-config-head h3 {
  margin: 3px 0 0;
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.025em;
}

.ai-config-head p {
  max-width: 56ch;
  margin: 5px 0 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.ai-config-body {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  align-items: start;
  gap: clamp(24px, 4vw, 48px);
}

.ai-config-main {
  display: grid;
  gap: var(--space-4);
  min-width: 0;
}

.ai-config-main .field {
  margin-bottom: 0;
}

.ai-config-aside {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
}

.ai-config-aside .ai-status {
  justify-self: start;
}

.ai-config-hint {
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.ai-aside-note {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: 1.65;
}

.ai-config-aside .text-link {
  justify-self: start;
  font-size: var(--text-xs);
}

.ai-config-result {
  margin: var(--space-3) 0 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--success) 28%, var(--border-subtle));
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-xs);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.ai-config-actions {
  align-items: center;
  margin-top: var(--space-4);
}

.ai-config-actions .text-link {
  margin-left: auto;
  font-size: var(--text-xs);
}

.ai-config-actions .btn-ghost {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
}

.ai-skill-card {
  max-width: none;
}

.ai-skill-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-4);
}

.ai-skill-head h3 {
  margin: 3px 0 0;
  font-size: var(--text-md);
  font-weight: 700;
}

.ai-skill-head p {
  max-width: 52ch;
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.ai-skill-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.ai-skill-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-2);
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.ai-skill-item code {
  align-self: start;
  padding: 2px 5px;
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 9px;
  white-space: nowrap;
}

.ai-skill-item strong {
  display: block;
  color: var(--text-primary);
  font-size: var(--text-xs);
  font-weight: 650;
}

.ai-skill-item span {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.5;
}

.editor-ai-button {
  color: var(--accent);
  font-weight: 650;
}

/* AI drawer */
.ai-backdrop {
  position: fixed;
  inset: var(--topbar-h) 0 0;
  z-index: 65;
  background: color-mix(in srgb, var(--bg-inverse) 24%, transparent);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.ai-drawer {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  z-index: 70;
  display: none;
  flex-direction: column;
  width: min(430px, 100vw);
  border-left: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  box-shadow: var(--shadow-xl);
}

.ai-drawer.is-open {
  display: flex;
  animation: ai-drawer-in var(--duration-base) var(--ease-out);
}

@keyframes ai-drawer-in {
  from { transform: translateX(102%); }
  to { transform: translateX(0); }
}

.ai-drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.ai-drawer-head h3 {
  margin: 3px 0 0;
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.025em;
}

.ai-drawer-body {
  flex: 1;
  min-height: 0;
  padding: 18px 22px 28px;
  overflow-y: auto;
}

.ai-model-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.ai-model-auto {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.ai-model-auto::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.ai-model-row .field {
  flex: 1;
  margin-bottom: 0;
}

.ai-model-row .text-link {
  font-size: var(--text-xs);
  white-space: nowrap;
}

.ai-note {
  margin: 0 0 var(--space-4);
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--warning) 28%, var(--border-subtle));
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  line-height: 1.6;
}

.ai-note a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-task-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: var(--space-4);
}

.ai-task {
  min-height: 44px;
  padding: 7px 6px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  transition: border-color var(--duration-fast), background var(--duration-fast), color var(--duration-fast);
}

.ai-task:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.ai-task.is-active {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border-subtle));
  background: var(--accent-soft);
  color: var(--accent);
}

.ai-task:disabled {
  opacity: 0.5;
  cursor: wait;
}

.ai-instruction {
  margin-bottom: var(--space-3);
}

.ai-instruction textarea {
  min-height: 58px;
  resize: vertical;
}

.ai-run {
  width: 100%;
  min-height: 42px;
}

.ai-result {
  margin-top: var(--space-4);
  padding: var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
}

.ai-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.03em;
}

.ai-result-head span:first-child {
  color: var(--accent);
  font-weight: 650;
}

.ai-result pre {
  max-height: 300px;
  margin: 0 0 var(--space-3);
  padding: 12px;
  overflow: auto;
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-result-actions {
  align-items: center;
}

.ai-result-actions .btn {
  min-height: 32px;
  padding: 0 10px;
  font-size: var(--text-xs);
}

.ai-drawer-foot {
  margin: var(--space-5) 0 0;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.6;
}

@media (max-width: 1100px) {
  .ai-skill-list { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .ai-drawer { width: 100%; }
  .ai-skill-head { flex-direction: column; align-items: flex-start; gap: var(--space-2); }
  .ai-task-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .ai-drawer.is-open { animation: none; }
}

@media (max-width: 900px) {
  .ai-config-body {
    grid-template-columns: minmax(0, 1fr);
  }
}
