:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --text: #152033;
  --muted: #64748b;
  --line: rgba(21, 32, 51, .1);
  --primary: #0f9f7a;
  --primary-dark: #0b7f64;
  --accent: #2563eb;
  --danger: #dc2626;
  --warning: #f59e0b;
  --shadow: 0 18px 45px rgba(15, 23, 42, .08);
  --radius: 24px;
  --radius-sm: 14px;
  --sidebar: 306px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #111c32;
  --surface-2: #17233c;
  --text: #e5e7eb;
  --muted: #9aa7bb;
  --line: rgba(226, 232, 240, .12);
  --primary: #34d399;
  --primary-dark: #10b981;
  --accent: #60a5fa;
  --danger: #fb7185;
  --shadow: 0 18px 45px rgba(0, 0, 0, .28);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  background:
    radial-gradient(circle at 16% 8%, rgba(15,159,122,.16), transparent 32rem),
    radial-gradient(circle at 82% 18%, rgba(37,99,235,.14), transparent 34rem),
    var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.topbar {
  position: fixed; z-index: 30; top: 0; left: 0; right: 0; height: 72px;
  display: flex; align-items: center; gap: 16px; padding: 0 22px;
  background: rgba(255,255,255,.78); backdrop-filter: blur(18px); border-bottom: 1px solid var(--line);
}
[data-theme="dark"] .topbar { background: rgba(15,23,42,.76); }
.brand { display:flex; align-items:center; gap:12px; min-width: 230px; }
.brand-mark { width:42px; height:42px; border-radius:14px; display:grid; place-items:center; background:linear-gradient(135deg,var(--primary),var(--accent)); color:white; font-weight:900; box-shadow: var(--shadow); }
.brand strong { display:block; font-size: 17px; letter-spacing:.2px; }
.brand small { display:block; color:var(--muted); font-size:12px; margin-top:2px; }
.toplinks { display:flex; align-items:center; gap:6px; flex:1; overflow:auto; }
.toplinks a { padding:8px 12px; border-radius:999px; color:var(--muted); white-space:nowrap; }
.toplinks a.active, .toplinks a:hover { color:var(--text); background:var(--surface-2); }
.top-actions { display:flex; align-items:center; gap:8px; }
.icon-button, .pill-button, .pill-link { border:1px solid var(--line); background:var(--surface); color:var(--text); border-radius:999px; min-height:40px; padding:0 13px; box-shadow:0 8px 24px rgba(15,23,42,.05); display:inline-flex; align-items:center; justify-content:center; }
.icon-button { width:40px; padding:0; }
.pill-button.active { background: rgba(15,159,122,.12); border-color: rgba(15,159,122,.35); color: var(--primary-dark); font-weight: 700; }
[data-theme="dark"] .pill-button.active { color: var(--primary); }
.mobile-only { display:none; }
.sidebar { position: fixed; top:72px; bottom:0; left:0; width: var(--sidebar); padding: 22px 16px; border-right:1px solid var(--line); overflow:auto; background: rgba(255,255,255,.52); backdrop-filter: blur(18px); z-index:20; }
[data-theme="dark"] .sidebar { background: rgba(15,23,42,.58); }
.sidebar-head { display:flex; align-items:flex-end; justify-content:space-between; margin-bottom:14px; }
.eyebrow { margin:0 0 6px; font-size:11px; text-transform:uppercase; letter-spacing:.14em; color:var(--primary-dark); font-weight:800; }
[data-theme="dark"] .eyebrow { color: var(--primary); }
.mode-switch { display:grid; grid-template-columns:1fr 1fr; gap:6px; padding:5px; border:1px solid var(--line); background:var(--surface); border-radius:999px; margin-bottom:12px; }
.mode-switch button { border:0; background:transparent; padding:10px 8px; border-radius:999px; color:var(--muted); }
.mode-switch button.active { background:linear-gradient(135deg,var(--primary),var(--accent)); color:#fff; font-weight:700; }
.filter-input, .admin-search, input, select, textarea { width:100%; border:1px solid var(--line); border-radius:14px; background:var(--surface); color:var(--text); padding:11px 13px; outline:none; }
.filter-input:focus, input:focus, textarea:focus, select:focus { border-color: rgba(15,159,122,.5); box-shadow: 0 0 0 4px rgba(15,159,122,.12); }
.category-list { display:grid; gap:8px; margin-top:12px; }
.category-item { border:1px solid transparent; background:transparent; color:var(--text); text-align:left; border-radius:16px; padding:12px; display:flex; align-items:center; gap:10px; transition:.16s ease; }
.category-item:hover { background:var(--surface-2); }
.category-item.active { background:var(--surface); border-color: rgba(15,159,122,.34); box-shadow: 0 10px 28px rgba(15,23,42,.06); }
.category-icon { width:28px; height:28px; border-radius:10px; display:grid; place-items:center; background:var(--surface-2); }
.category-name { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.category-count { font-size:12px; color:var(--muted); }
.disabled-badge { font-size:11px; font-weight:800; color:var(--muted); background:var(--surface-2); border:1px solid var(--line); border-radius:999px; padding:3px 7px; }
.is-disabled { opacity:.55; }
.sidebar-note { color:var(--muted); font-size:12px; line-height:1.5; }
.main-content { grid-column: 2; padding: 96px 28px 40px; max-width: 1260px; width:100%; }
.hero-card, .search-card, .links-section, .admin-toolbar, .editor-section, .admin-list-panel, .admin-editor-panel, .cse-panel { background: rgba(255,255,255,.82); border:1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
[data-theme="dark"] .hero-card, [data-theme="dark"] .search-card, [data-theme="dark"] .links-section, [data-theme="dark"] .admin-toolbar, [data-theme="dark"] .editor-section, [data-theme="dark"] .admin-list-panel, [data-theme="dark"] .admin-editor-panel, [data-theme="dark"] .cse-panel { background: rgba(17,28,50,.82); }
.hero-card { padding:30px; display:flex; align-items:flex-end; justify-content:space-between; gap:20px; margin-bottom:18px; }
.hero-card h1 { margin:0; font-size: clamp(28px, 4vw, 48px); line-height:1.04; letter-spacing:-.04em; }
.hero-card p:not(.eyebrow) { color:var(--muted); max-width: 760px; line-height:1.7; }
.stats { display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }
.stats.vertical { display:grid; justify-content:stretch; }
.stat-pill { padding:9px 12px; background:var(--surface-2); border:1px solid var(--line); border-radius:999px; color:var(--muted); font-size:13px; }
.stat-pill strong { color:var(--text); margin-right:4px; }
.search-card { padding:22px; }
.search-header { display:flex; justify-content:space-between; align-items:center; gap:14px; margin-bottom:14px; }
.search-header h2 { margin:0; font-size:26px; }
.count-pill { padding:8px 12px; border-radius:999px; background:rgba(37,99,235,.1); color:var(--accent); font-weight:800; }
.search-form { display:grid; grid-template-columns: minmax(0,1fr) auto; gap:10px; }
.search-form input { border-radius:18px; font-size:17px; padding:16px 18px; }
.search-form button, .primary-button { border:0; background:linear-gradient(135deg,var(--primary),var(--accent)); color:#fff; border-radius:16px; padding:0 24px; font-weight:800; min-height:48px; }
.secondary-button, .small-button, .danger-button { border:1px solid var(--line); background:var(--surface); color:var(--text); border-radius:14px; padding:10px 14px; min-height:40px; }
.danger-button { color: var(--danger); border-color: rgba(220,38,38,.24); }
.small-button { padding:8px 12px; min-height:34px; }
.hint { margin:10px 2px 0; color:var(--muted); font-size:13px; }
.engine-grid { margin-top:16px; display:grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap:10px; }
.engine-button { min-height:72px; border:1px solid var(--line); background:var(--surface); color:var(--text); border-radius:18px; padding:13px; text-align:left; display:flex; flex-direction:column; gap:4px; }
.engine-button:hover { transform: translateY(-1px); box-shadow:0 12px 30px rgba(15,23,42,.08); }
.engine-button.active { border-color:rgba(15,159,122,.5); background:linear-gradient(135deg, rgba(15,159,122,.13), rgba(37,99,235,.11)); }
.engine-button small { color:var(--muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:100%; }
.links-section { margin-top:18px; padding:22px; }
.links-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap:14px; }
.link-group { border:1px solid var(--line); background:var(--surface); border-radius:18px; padding:16px; }
.link-group h3 { margin:0 0 12px; font-size:16px; }
.link-list { display:grid; gap:8px; }
.link-list a { color:var(--muted); padding:8px 10px; border-radius:10px; background:var(--surface-2); display:flex; justify-content:space-between; align-items:center; }
.link-list a:hover { color:var(--text); }
.hero-split { display:grid; grid-template-columns:minmax(0,1.25fr) minmax(280px,.75fr); gap:20px; align-items:stretch; }
.hero-main { display:grid; gap:12px; }
.hero-side { display:grid; gap:14px; align-content:start; }
.hero-actions { display:flex; gap:10px; flex-wrap:wrap; }
.hero-note { border:1px solid var(--line); background:var(--surface-2); border-radius:20px; padding:16px; color:var(--muted); line-height:1.6; }
.trust-strip, .platform-grid, .module-grid { display:grid; gap:14px; }
.trust-strip { grid-template-columns:repeat(auto-fit,minmax(160px,1fr)); }
.platform-grid { grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); margin:18px 0; }
.module-grid { grid-template-columns:repeat(auto-fit,minmax(260px,1fr)); margin:0 0 18px; }
.feature-card, .module-card { border:1px solid var(--line); background:rgba(255,255,255,.82); border-radius:var(--radius); box-shadow:var(--shadow); padding:20px; }
[data-theme="dark"] .feature-card, [data-theme="dark"] .module-card { background:rgba(17,28,50,.82); }
.feature-card h3, .module-card h3 { margin:0 0 10px; font-size:20px; letter-spacing:-.02em; }
.feature-card p:not(.eyebrow), .module-card p:not(.eyebrow) { margin:0; color:var(--muted); line-height:1.7; }
.module-card { display:flex; flex-direction:column; justify-content:space-between; gap:16px; }
.module-card .secondary-button { width:max-content; }
.aggregate-results { margin-top:18px; }
.cse-panel { padding:0; overflow:hidden; }
.cse-panel-header { display:flex; justify-content:space-between; align-items:center; padding:16px 18px; border-bottom:1px solid var(--line); }
.cse-frame { width:100%; height:680px; border:0; background:white; }
.empty-state, .empty-mini { padding:24px; text-align:center; color:var(--muted); }
mark { background:rgba(245,158,11,.28); color:inherit; border-radius:4px; padding:0 2px; }
.backdrop { position:fixed; inset:0; background:rgba(15,23,42,.18); z-index:25; display:none; opacity:0; transition:opacity .18s ease; }
.backdrop.show { display:block; opacity:1; }
.inline-actions { display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
/* Admin */
.admin-body .topbar { position:sticky; }
.admin-shell { min-height:100vh; }
.admin-main { max-width:1320px; margin:0 auto; padding:24px; }
.admin-hero { margin-bottom:18px; }
.admin-toolbar { padding:14px; display:flex; justify-content:space-between; gap:12px; align-items:center; margin-bottom:18px; position:sticky; top:0; z-index:10; }
.admin-tabs { display:flex; gap:8px; flex-wrap:wrap; }
.admin-tabs button { border:1px solid var(--line); background:var(--surface); color:var(--muted); padding:10px 12px; border-radius:999px; }
.admin-tabs button.active { background:linear-gradient(135deg,var(--primary),var(--accent)); color:#fff; border-color:transparent; }
.admin-actions { display:flex; gap:8px; flex-wrap:wrap; }
.admin-panel { display:none; }
.admin-panel.active { display:block; }
.admin-grid.two-columns { display:grid; grid-template-columns: 330px minmax(0,1fr); gap:18px; align-items:start; }
.admin-list-panel, .admin-editor-panel, .editor-section { padding:18px; }
.admin-list-panel { position:sticky; top: 96px; }
.admin-panel-heading { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:14px; }
.admin-panel-heading h2, .admin-panel-heading h3 { margin:0; }
.admin-list, .compact-list { display:grid; gap:8px; margin-top:12px; }
.list-row { border:1px solid var(--line); background:var(--surface); border-radius:14px; padding:11px 12px; text-align:left; color:var(--text); display:flex; justify-content:space-between; gap:10px; align-items:center; }
.list-row.active { border-color:rgba(15,159,122,.5); background:rgba(15,159,122,.08); }
.row-title { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.row-meta { color:var(--muted); font-size:12px; }
.editor-section + .editor-section { margin-top:18px; }
.form-grid { display:grid; gap:12px; margin-bottom:12px; }
.form-grid.two-columns { grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid.three-columns { grid-template-columns: repeat(3, minmax(0,1fr)); }
.form-grid.compact { gap:10px; }
label { display:grid; gap:6px; color:var(--muted); font-size:13px; }
.checkbox-label { display:flex; align-items:center; gap:8px; padding:10px 0; }
.checkbox-label input { width:auto; }
.split-editor { display:grid; grid-template-columns: 240px minmax(0,1fr); gap:16px; align-items:start; }
.admin-form, .nested-form { display:grid; gap:12px; }
.soft-divider { border:0; border-top:1px solid var(--line); margin:16px 0; }
.code-box { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; min-height:360px; white-space:pre; }
.audit-output { display:grid; gap:10px; }
.audit-item { padding:12px 14px; border:1px solid var(--line); border-radius:14px; background:var(--surface); }
.audit-item.warn { border-color: rgba(245,158,11,.35); }
.audit-item.error { border-color: rgba(220,38,38,.35); }
@media (max-width: 980px) {
  .app-shell { display:block; }
  .topbar { height:64px; padding:0 14px; }
  .brand { min-width:0; }
  .toplinks { display:none; }
  .mobile-only { display:inline-flex; }
  .sidebar { transform: translateX(-105%); transition:.2s ease; top:64px; background:var(--surface); }
  .sidebar.open { transform: translateX(0); }
  .main-content { padding:84px 14px 28px; }
  .hero-card { display:block; padding:22px; }
  .hero-split { grid-template-columns:1fr; }
  .stats { justify-content:flex-start; }
  .search-form { grid-template-columns:1fr; }
  .search-form button { width:100%; }
  .engine-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .admin-main { padding:14px; }
  .admin-toolbar { position:static; display:block; }
  .admin-actions { margin-top:12px; }
  .admin-grid.two-columns, .split-editor, .form-grid.two-columns, .form-grid.three-columns { grid-template-columns:1fr; }
  .admin-list-panel { position:static; }
}
@media (max-width: 560px) {
  .brand small { display:none; }
  .top-actions { gap:5px; }
  .pill-button { padding:0 10px; }
  .hero-card h1 { font-size:30px; }
  .engine-grid { grid-template-columns:1fr; }
  .links-grid { grid-template-columns:1fr; }
  .hero-actions { display:grid; grid-template-columns:1fr; }
  .module-card .secondary-button { width:100%; }
}

.mode-switch.single { grid-template-columns: 1fr; }


/* Mobile sidebar fix: make the category drawer readable and avoid the heavy grey overlay. */
@media (max-width: 980px) {
  body.menu-open { overflow: hidden; }
  .sidebar {
    top: 64px;
    bottom: 0;
    left: 0;
    width: min(86vw, 360px);
    max-width: calc(100vw - 44px);
    padding: 18px 14px 28px;
    transform: translateX(-110%);
    transition: transform .22s ease;
    background: var(--surface);
    opacity: 1;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: 18px 0 40px rgba(15, 23, 42, .18);
    border-right: 1px solid var(--line);
    z-index: 40;
  }
  [data-theme="dark"] .sidebar {
    background: var(--surface);
    box-shadow: 18px 0 40px rgba(0, 0, 0, .42);
  }
  .sidebar.open { transform: translateX(0); }
  .backdrop {
    top: 64px;
    background: rgba(15, 23, 42, .16);
    z-index: 35;
  }
  [data-theme="dark"] .backdrop { background: rgba(0, 0, 0, .32); }
}
@media (max-width: 560px) {
  .topbar { gap: 8px; }
  .brand strong { font-size: 16px; }
  .brand-mark { width: 40px; height: 40px; }
  .icon-button, .pill-button { min-height: 40px; }
  .top-actions { margin-left: auto; }
}
