/* ===================================================================
   Grabber — Apple-style design system
   =================================================================== */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --surface-3: #ececee;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #8e8e93;
  --border: #d2d2d7;
  --border-soft: #e8e8ed;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, 0.1);
  --danger: #ff3b30;
  --green: #34c759;
  --amber: #ff9f0a;
  --purple: #af52de;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
  --radius: 14px;
  --radius-lg: 20px;
  --radius-sm: 9px;
  --sidebar-w: 248px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --surface-3: #3a3a3c;
    --text: #f5f5f7;
    --muted: #98989d;
    --faint: #8e8e93;
    --border: #38383a;
    --border-soft: #2c2c2e;
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --accent-soft: rgba(10, 132, 255, 0.18);
    --danger: #ff453a;
    --green: #30d158;
    --amber: #ffd60a;
    --purple: #bf5af2;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --surface-3: #3a3a3c;
  --text: #f5f5f7;
  --muted: #98989d;
  --faint: #8e8e93;
  --border: #38383a;
  --border-soft: #2c2c2e;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-soft: rgba(10, 132, 255, 0.18);
  --danger: #ff453a;
  --green: #30d158;
  --amber: #ffd60a;
  --purple: #bf5af2;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}
.hidden { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--accent-soft); }

/* ---- Buttons ---- */
.btn {
  font-family: inherit; font-size: 0.92rem; font-weight: 500;
  padding: 9px 18px; border-radius: 980px; border: 1px solid transparent;
  cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: rgba(255, 59, 48, 0.1); border-color: var(--danger); }
.btn-sm { padding: 6px 13px; font-size: 0.82rem; }

/* ---- Inputs ---- */
input[type="text"], input[type="password"], select, textarea {
  font-family: inherit; font-size: 0.95rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 14px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
select { cursor: pointer; }

.card {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.hint { color: var(--muted); font-size: 0.82rem; }

/* ===================================================================
   Login page
   =================================================================== */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background:
    radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border-soft); border-radius: 22px;
  box-shadow: var(--shadow-lg); padding: 40px 36px; text-align: center;
}
.login-logo {
  width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: #fff; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.02em; }
.login-card .sub { color: var(--muted); font-size: 0.9rem; margin-bottom: 26px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card input { text-align: center; padding: 13px; }
.login-card .btn { width: 100%; padding: 12px; }
.login-error { color: var(--danger); font-size: 0.85rem; min-height: 1.1em; }
.login-foot { margin-top: 22px; color: var(--faint); font-size: 0.78rem; }

/* ===================================================================
   App shell
   =================================================================== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border-soft); display: flex; flex-direction: column;
  padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px; font-size: 1.15rem;
  font-weight: 650; letter-spacing: -0.02em; padding: 6px 10px 20px;
}
.brand-logo {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 12px; border: none; background: transparent; cursor: pointer;
  border-radius: 10px; font-family: inherit; font-size: 0.93rem; font-weight: 450;
  color: var(--text); text-align: left; transition: background 0.12s;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.nav-item svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 12px; }
.db-pill {
  display: flex; align-items: center; gap: 7px; font-size: 0.78rem; color: var(--muted);
  padding: 7px 12px; background: var(--surface-2); border-radius: 10px;
}
.db-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.db-pill.on .dot { background: var(--green); }
.db-pill.off .dot { background: var(--amber); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 32px; background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px); border-bottom: 1px solid var(--border-soft);
}
.topbar h1 { font-size: 1.4rem; font-weight: 650; letter-spacing: -0.02em; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.scroll { flex: 1; overflow-y: auto; padding: 28px 32px 60px; }
.view { max-width: 1080px; margin: 0 auto; }

.sidebar-toggle {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 50;
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 18px; cursor: pointer;
}

/* ---- Search view ---- */
.search-panel { padding: 22px; margin-bottom: 20px; }
.profile-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.profile-row label { font-size: 0.82rem; color: var(--muted); font-weight: 500; }
.profile-row select { min-width: 200px; }
.search-row { display: flex; gap: 10px; flex-wrap: wrap; }
.search-row #q { flex: 1 1 300px; font-size: 1.02rem; padding: 13px 16px; }
.search-row #type { flex: 0 0 auto; }
#detected { margin-top: 10px; min-height: 1em; }

.status { text-align: center; color: var(--muted); min-height: 1.4em; margin: 10px 0; }
.spinner {
  display: inline-block; width: 15px; height: 15px; vertical-align: -2px; margin-right: 8px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.results-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 18px;
}
.summary { font-weight: 600; font-size: 0.95rem; }
.segmented {
  display: inline-flex; background: var(--surface-3); border-radius: 9px; padding: 2px;
}
.seg {
  border: none; background: transparent; cursor: pointer; font-family: inherit;
  font-size: 0.85rem; font-weight: 500; color: var(--muted); padding: 5px 16px;
  border-radius: 7px; transition: all 0.15s;
}
.seg.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.downloads { display: flex; align-items: center; gap: 6px; }
.downloads span { color: var(--muted); font-size: 0.8rem; }
.dl, .rbtn {
  padding: 6px 12px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-soft); border-radius: 8px; cursor: pointer; font-size: 0.8rem;
  font-family: inherit;
}
.dl:hover, .rbtn:hover { border-color: var(--accent); color: var(--accent); }

.cache-banner, .banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid transparent;
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 0.86rem;
}
.banner.warn { background: rgba(255, 159, 10, 0.12); color: #9a6a00; }
:root[data-theme="dark"] .banner.warn, :root:not([data-theme="light"]) .banner.warn { color: var(--amber); }
.cache-banner button {
  padding: 5px 13px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px; cursor: pointer; font-size: 0.8rem;
}

.group { margin-bottom: 26px; }
.group h3 {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--faint); margin: 0 0 12px; font-weight: 600;
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.result-card {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, transform 0.15s;
}
.result-card:hover { box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 11px; }
.icon {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 8px; object-fit: contain;
  background: var(--surface-2); border: 1px solid var(--border-soft);
}
.icon.emoji { display: inline-flex; align-items: center; justify-content: center; font-size: 16px; }
.card-head .title { font-weight: 600; font-size: 0.92rem; flex: 1 1 auto; min-width: 0; }
.result-card .detail { color: var(--muted); font-size: 0.85rem; margin-top: 9px; word-break: break-word; }
.result-card .meta { color: var(--faint); font-size: 0.74rem; margin-top: 9px; }
.badge {
  flex: 0 0 auto; font-size: 0.66rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.03em; padding: 3px 8px; border-radius: 6px;
  background: var(--surface-3); color: var(--muted);
}
.badge.high { background: rgba(52, 199, 89, 0.15); color: #1a7f37; }
.badge.medium { background: var(--accent-soft); color: var(--accent); }
.badge.low { background: rgba(255, 159, 10, 0.15); color: #9a6a00; }
.badge.lead { background: rgba(175, 82, 222, 0.14); color: var(--purple); }
:root[data-theme="dark"] .badge.high, :root:not([data-theme="light"]) .badge.high { color: var(--green); }
:root[data-theme="dark"] .badge.low, :root:not([data-theme="light"]) .badge.low { color: var(--amber); }

.errors {
  background: rgba(255, 59, 48, 0.08); border: 1px solid rgba(255, 59, 48, 0.25);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px;
  font-size: 0.82rem; color: var(--danger);
}
.empty-state { color: var(--muted); text-align: center; padding: 40px 20px; }

/* ---- Graph ---- */
.graph-controls {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  margin-bottom: 14px; color: var(--muted); font-size: 0.85rem;
}
.graph-controls label { cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }
.graph-hint { font-size: 0.78rem; color: var(--faint); }
#graph-canvas {
  height: 620px; border: 1px solid var(--border-soft); border-radius: var(--radius-lg);
  background: var(--surface); overflow: hidden; box-shadow: var(--shadow-sm);
}

/* ---- Profiles / dashboard ---- */
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.view-head .sub { color: var(--muted); font-size: 0.9rem; }
.pcard {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.pcard-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pcard-head .pname { font-weight: 650; font-size: 1.1rem; letter-spacing: -0.01em; }
.pcard-head .pmeta { color: var(--faint); font-size: 0.8rem; }
.pcard-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.pcard-actions button {
  padding: 6px 12px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-soft); border-radius: 8px; cursor: pointer;
  font-size: 0.78rem; font-family: inherit;
}
.pcard-actions button:hover { border-color: var(--accent); color: var(--accent); }
.pcard-actions .danger:hover { border-color: var(--danger); color: var(--danger); }
.pcard-note { color: var(--muted); font-size: 0.86rem; margin-top: 10px; }
.pcard-searches { margin-top: 14px; border-top: 1px solid var(--border-soft); padding-top: 12px; }
.srow { display: flex; gap: 10px; align-items: center; font-size: 0.82rem; padding: 5px 0; color: var(--muted); }
.stype {
  background: var(--surface-3); border-radius: 20px; padding: 2px 10px;
  font-size: 0.72rem; color: var(--text); font-weight: 500;
}

/* ---- Sources ---- */
.sources-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.mod {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.mod-top { display: flex; align-items: center; gap: 9px; }
.mod .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.mod.on .dot { background: var(--green); }
.mod.off .dot { background: var(--faint); }
.mod .mname { font-weight: 600; font-size: 0.9rem; }
.mod .reason { color: var(--muted); font-size: 0.78rem; margin-top: 7px; }
.mod .types { color: var(--faint); font-size: 0.75rem; margin-top: 4px; }

/* ---- Settings ---- */
.settings-section { margin-bottom: 26px; }
.settings-section h2 { font-size: 1.05rem; font-weight: 650; margin: 0 0 12px; letter-spacing: -0.01em; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 15px 18px; border-bottom: 1px solid var(--border-soft);
}
.setting-row:last-child { border-bottom: none; }
.setting-row .label { font-weight: 500; font-size: 0.92rem; }
.setting-row .desc { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.setting-list { background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.82rem;
  background: var(--surface-2); padding: 2px 7px; border-radius: 6px; }

/* ---- Profile detail (dossier) ---- */
#profile-back { margin-bottom: 14px; }
.profile-hero { padding: 22px 24px; margin-bottom: 20px; }
.hero-main { display: flex; align-items: center; gap: 16px; }
.hero-avatar {
  width: 58px; height: 58px; border-radius: 16px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 600; overflow: hidden;
}
.hero-avatar img { width: 100%; height: 100%; object-fit: cover; }
.hero-id { flex: 1 1 auto; min-width: 0; }
.hero-id h2 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bio-grid { margin-top: 18px; display: flex; flex-direction: column; gap: 20px; }
.bio-gtitle { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); font-weight: 700; margin-bottom: 9px; }
.bio-gfields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 11px 24px; }
.bio-field .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); }
.bio-field .v { font-size: 0.92rem; margin-top: 2px; word-break: break-word; }
.bio-summary { margin-top: 16px; color: var(--muted); font-size: 0.92rem; line-height: 1.6; white-space: pre-wrap; }

.dsec {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow-sm);
}
.dsec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dsec-head h3 { margin: 0; font-size: 1rem; font-weight: 650; }
.dsec-head .add-group { display: flex; gap: 6px; flex-wrap: wrap; }
.dsec-empty { color: var(--faint); font-size: 0.85rem; padding: 6px 0; }
.ditem {
  display: flex; align-items: flex-start; gap: 12px; padding: 11px 0;
  border-top: 1px solid var(--border-soft);
}
.ditem:first-child { border-top: none; }
.ditem .ibody { flex: 1 1 auto; min-width: 0; }
.ditem .ititle { font-weight: 550; font-size: 0.92rem; word-break: break-word; }
.ditem .inote { color: var(--muted); font-size: 0.84rem; margin-top: 3px; white-space: pre-wrap; word-break: break-word; }
.ditem .idel {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--border-soft);
  background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1;
}
.ditem .idel:hover { border-color: var(--danger); color: var(--danger); }
.ibadge {
  font-size: 0.68rem; font-weight: 600; padding: 2px 8px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent); margin-left: 6px;
}
.id-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.id-chip {
  display: inline-flex; gap: 6px; align-items: center; font-size: 0.82rem; padding: 5px 11px;
  background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 20px;
}
.id-chip b { font-weight: 600; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.media-item { position: relative; border: 1px solid var(--border-soft); border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.media-item img, .media-item video { width: 100%; display: block; max-height: 220px; object-fit: cover; }
.media-item audio { width: 100%; }
.media-item .mcap { padding: 7px 10px; font-size: 0.76rem; color: var(--muted); }
.media-item .idel { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,0.55); color: #fff; border: none; }

/* confidence badge */
.conf { font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 8px; border-radius: 6px; vertical-align: middle; }
.conf.high { background: rgba(52, 199, 89, 0.16); color: #1a7f37; }
.conf.medium { background: rgba(255, 159, 10, 0.16); color: #9a6a00; }
.conf.low { background: var(--surface-3); color: var(--muted); }
:root[data-theme="dark"] .conf.high, :root:not([data-theme="light"]) .conf.high { color: var(--green); }
:root[data-theme="dark"] .conf.medium, :root:not([data-theme="light"]) .conf.medium { color: var(--amber); }

/* item meta rows + POC */
.imeta-row { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; }
.imeta { font-size: 0.82rem; color: var(--muted); }
.imeta b { color: var(--text); font-weight: 600; }
.poc { display: inline-block; margin-top: 10px; max-width: 220px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border-soft); }
.poc img, .poc { max-height: 160px; }
.poc img { display: block; width: 100%; height: auto; }
video.poc { width: 240px; max-height: 160px; }
audio.poc { margin-top: 10px; width: 260px; }
.poc-file { display: inline-block; margin-top: 10px; font-size: 0.82rem; }

/* timeline */
.timeline { position: relative; padding-left: 8px; }
.tl-item { display: flex; gap: 14px; align-items: flex-start; padding: 10px 0; border-left: 2px solid var(--border); margin-left: 6px; padding-left: 16px; position: relative; }
.tl-item::before { content: ""; position: absolute; left: -7px; top: 15px; width: 11px; height: 11px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
.tl-date { flex: 0 0 110px; font-weight: 600; font-size: 0.85rem; color: var(--accent); }
.tl-body { flex: 1 1 auto; min-width: 0; }

/* form modal fields */
#form-fields .field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
#form-fields select { font-family: inherit; }
#form-fields .field label { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
#form-fields textarea { resize: vertical; font-family: inherit; }

/* ---- Methods panel ---- */
.methods-panel {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); margin-bottom: 18px; box-shadow: var(--shadow-sm);
}
.methods-panel summary {
  cursor: pointer; padding: 13px 16px; font-weight: 600; font-size: 0.88rem;
  list-style: none; display: flex; align-items: center;
}
.methods-panel summary::-webkit-details-marker { display: none; }
.mcount { color: var(--faint); font-weight: 400; margin-left: 6px; }
#methods-list { padding: 0 16px 10px; }
.method-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 0;
  border-top: 1px solid var(--border-soft); flex-wrap: wrap;
}
.method-row .mlabel { flex: 0 0 170px; font-size: 0.82rem; font-weight: 500; }
.method-row .mcmd {
  flex: 1 1 260px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.76rem; color: var(--muted); background: var(--surface-2);
  padding: 7px 11px; border-radius: 8px; word-break: break-all;
}
.mkind {
  flex: 0 0 auto; font-size: 0.62rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.03em; padding: 3px 7px; border-radius: 5px;
}
.mkind.cli { background: rgba(52, 199, 89, 0.15); color: #1a7f37; }
.mkind.api { background: var(--accent-soft); color: var(--accent); }
.mkind.http { background: var(--accent-soft); color: var(--accent); }
.mkind.offline { background: var(--surface-3); color: var(--muted); }
.mkind.builder { background: rgba(175, 82, 222, 0.14); color: var(--purple); }
:root[data-theme="dark"] .mkind.cli, :root:not([data-theme="light"]) .mkind.cli { color: var(--green); }

/* ---- Live-tools footer ---- */
.live-footer { margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--border-soft); }
.lf-title {
  font-size: 0.73rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--faint); font-weight: 600; margin-bottom: 11px;
}
.lf-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.lf-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem;
  padding: 5px 11px; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: 20px; color: var(--muted); box-shadow: var(--shadow-sm);
}
.lf-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

/* ===================================================================
   Modal + toast
   =================================================================== */
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover { filter: brightness(1.08); }

.modal-root { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-root.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(4px); animation: fade 0.15s ease; }
.modal-card {
  position: relative; width: min(440px, 100%); background: var(--surface);
  border: 1px solid var(--border-soft); border-radius: 20px; box-shadow: var(--shadow-lg);
  padding: 26px; animation: modalIn 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-height: 86vh; overflow-y: auto;
}
.modal-card h3 { margin: 0 0 8px; font-size: 1.15rem; font-weight: 650; letter-spacing: -0.01em; }
.modal-card p { margin: 0 0 18px; color: var(--muted); font-size: 0.9rem; }
.modal-card p.hidden { display: none; }
.modal-input { width: 100%; margin-bottom: 20px; }
.modal-input.hidden { display: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.toast-root {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  z-index: 1100; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 12px 20px; font-size: 0.88rem; max-width: 90vw;
  transition: opacity 0.2s; animation: toastIn 0.2s ease;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--green); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ===================================================================
   Responsive
   =================================================================== */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%);
    transition: transform 0.25s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  .topbar { padding-left: 64px; }
  .scroll { padding: 20px 18px 50px; }
  .topbar, .scroll { padding-right: 18px; }
  .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 35; }
}

/* ===================================================================
   Tool directory + AI summary
   =================================================================== */
.tools-bar { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px 16px; margin-bottom: 16px; }
.tools-bar #tools-q { flex: 1 1 280px; }
.tools-bar #tools-cat { flex: 0 0 auto; min-width: 180px; }
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tool-card {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow-sm);
}
.tool-top { display: flex; align-items: center; gap: 8px; }
.tfav { width: 18px; height: 18px; border-radius: 4px; flex-shrink: 0; }
.tool-name { font-weight: 600; font-size: 0.9rem; word-break: break-word; }
.tool-cat {
  display: inline-block; font-size: 0.68rem; text-transform: capitalize; margin-top: 7px;
  padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent);
}
.tool-desc { color: var(--muted); font-size: 0.82rem; margin-top: 8px; line-height: 1.45; }
.tools-more { text-align: center; margin-top: 18px; }
.tools-more.hidden { display: none; }

.ai-panel {
  background: var(--surface); border: 1px solid var(--accent-soft);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  padding: 16px 18px; margin-bottom: 18px;
}
.ai-panel.hidden { display: none; }
.ai-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.ai-title { font-weight: 650; font-size: 0.98rem; }
.ai-model { font-size: 0.72rem; color: var(--faint); font-family: ui-monospace, Menlo, monospace; }
.ai-head .btn { margin-left: auto; }
.ai-body {
  white-space: pre-wrap; font-size: 0.9rem; line-height: 1.6; color: var(--text);
}
