/* ============================================================
   SIGMA RULE BUILDER — NOXXA design system
   Space Grotesk + Space Mono · dark #080808 · minimal
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=Space+Mono:wght@400;700&display=swap');

:root {
  --bg:          #080808;
  --bg-1:        #0f0f0f;
  --bg-2:        #141414;
  --bg-3:        #1a1a1a;
  --border:      #222222;
  --border-soft: #1a1a1a;
  --border-focus:#444444;
  --text:        #e2e2e2;
  --text-muted:  #555555;
  --text-dim:    #2a2a2a;
  --accent:      #e2e2e2;
  --white:       #ffffff;
  --ok:          #4ade80;
  --warn:        #facc15;
  --err:         #f87171;
  --info:        #60a5fa;
  --lvl-informational: #60a5fa;
  --lvl-low:           #4ade80;
  --lvl-medium:        #facc15;
  --lvl-high:          #fb923c;
  --lvl-critical:      #f87171;
  --font-sans: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'Space Mono', 'Courier New', monospace;
  --r-sm: 4px; --r-md: 8px; --r-lg: 12px;
  --toolbar-h: 52px;
  --nav-h:     56px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; font-size: 15px; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font-sans); font-weight: 400; line-height: 1.6;
  -webkit-font-smoothing: antialiased; overflow-x: hidden; min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Typography ─────────────────────────────────────────── */

.mono     { font-family: var(--font-mono); }
.mono-inp { font-family: var(--font-mono); font-size: 0.8rem; }
.label-xs {
  font-family: var(--font-mono); font-size: 0.65rem;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted);
}
.hint      { font-size: 0.75rem; color: var(--text-muted); margin-left: 0.4rem; }
.hint-text { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.35rem; line-height: 1.5; }
.hint-link { font-size: 0.8rem; color: var(--text-muted); display: inline-block; margin-top: 0.35rem; }
.hint-link:hover { color: var(--text); }
.req        { color: var(--err); font-size: 0.8rem; }
.error-text { color: var(--err); font-size: 0.85rem; margin-bottom: 0.75rem; }
.text-muted { color: var(--text-muted); }

code {
  font-family: var(--font-mono); font-size: 0.75rem;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 5px;
}

/* ── NAV ────────────────────────────────────────────────── */

#nav {
  position: sticky; top: 0; z-index: 100;
  height: var(--nav-h); background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center;
}
.nav-inner {
  width: 100%; max-width: 1600px; margin: 0 auto;
  padding: 0 1.5rem; display: flex; align-items: center; gap: 1.5rem;
}
.nav-logo {
  font-family: var(--font-mono); font-size: 0.85rem; font-weight: 700;
  letter-spacing: 0.1em; color: var(--white); flex-shrink: 0;
}
.nav-center { flex: 1; }
.nav-tool-label {
  font-family: var(--font-mono); font-size: 0.7rem;
  letter-spacing: 0.15em; text-transform: uppercase; color: var(--text-muted);
}
.nav-links { list-style: none; display: flex; gap: 1.5rem; flex-shrink: 0; }
.nav-links a { font-size: 0.8rem; color: var(--text-muted); transition: color 0.15s; }
.nav-links a:hover { color: var(--text); }

/* ── TOOLBAR ────────────────────────────────────────────── */

.toolbar {
  background: var(--bg-1); border-bottom: 1px solid var(--border);
  height: var(--toolbar-h); display: flex; align-items: center;
}
.toolbar-inner {
  width: 100%; max-width: 1600px; margin: 0 auto;
  padding: 0 1.5rem; display: flex; align-items: center;
  gap: 1rem;
}
.toolbar-left  { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.toolbar-right { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; margin-left: auto; }

/* Tabs live inside the toolbar */
.toolbar-tabs {
  display: flex; align-items: stretch; flex: 1;
  justify-content: flex-start; gap: 0;
  height: var(--toolbar-h);
}
.toolbar-tabs .tab-btn {
  border-bottom: 2px solid transparent;
  border-radius: 0;
  height: 100%;
  padding: 0 1rem;
}

.lint-badge {
  font-family: var(--font-mono); font-size: 0.65rem; letter-spacing: 0.05em;
  padding: 2px 8px; border-radius: 999px; border: 1px solid;
}
.lint-badge.ok  { color: var(--ok);  border-color: rgba(74,222,128,0.25); background: rgba(74,222,128,0.06); }
.lint-badge.err { color: var(--err); border-color: rgba(248,113,113,0.3); background: rgba(248,113,113,0.06); }

/* ── BUTTONS ────────────────────────────────────────────── */

.btn-tool {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.04em;
  padding: 5px 12px; background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  cursor: pointer; transition: background 0.15s, border-color 0.15s; white-space: nowrap;
}
.btn-tool:hover { background: var(--bg-2); border-color: var(--border-focus); }
.btn-tool.accent { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-tool.accent:hover { background: var(--white); border-color: var(--white); }
.btn-tool.small { font-size: 0.65rem; padding: 3px 9px; }

.btn-icon {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--text-muted); cursor: pointer; font-size: 1rem; line-height: 1; flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-icon:hover { background: var(--bg-3); color: var(--text); border-color: var(--border-focus); }
.btn-icon.danger:hover { background: rgba(248,113,113,0.1); border-color: var(--err); color: var(--err); }
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }

.btn-add {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.05em;
  color: var(--text-muted); background: transparent;
  border: 1px dashed var(--border); border-radius: var(--r-sm);
  padding: 4px 12px; cursor: pointer; margin-top: 0.5rem;
  transition: color 0.15s, border-color 0.15s; width: 100%; text-align: left;
}
.btn-add:hover { color: var(--text); border-color: var(--border-focus); }
.btn-add.small { width: auto; padding: 2px 8px; font-size: 0.65rem; }
.group-add { margin-top: 0.75rem; }

.btn-inline-link {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-family: var(--font-sans); font-size: inherit; padding: 0;
  text-decoration: underline; text-underline-offset: 2px;
}
.btn-inline-link:hover { color: var(--text); }

/* ── LAYOUT ─────────────────────────────────────────────── */

.builder-layout {
  display: grid; grid-template-columns: 1fr 420px;
  height: calc(100vh - var(--nav-h) - var(--toolbar-h) - 48px);
  height: calc(100dvh - var(--nav-h) - var(--toolbar-h) - 48px);
  min-height: 400px; max-width: 1600px; margin: 0 auto;
  transition: grid-template-columns 0.2s ease;
}
.builder-layout.matrix-mode {
  grid-template-columns: 1fr 0px;
  max-width: 100%;
}
.builder-layout.matrix-mode .preview-panel {
  overflow: hidden;
  border: none;
}
@media (max-width: 1024px) {
  .builder-layout { grid-template-columns: 1fr; }
  .preview-panel { display: none; }
}

/* ── FORM PANEL ─────────────────────────────────────────── */

.form-panel {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border); overflow: hidden;
}

/* ── TABS ────────────────────────────────────────────────── */

.tab-nav {
  display: flex; border-bottom: 1px solid var(--border);
  background: var(--bg-1); flex-shrink: 0;
}
.tab-btn {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.06em;
  text-transform: uppercase; padding: 0 1.25rem; height: 40px;
  background: transparent; border: none; border-bottom: 2px solid transparent;
  color: var(--text-muted); cursor: pointer; display: flex; align-items: center;
  gap: 0.4rem; transition: color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--white); border-bottom-color: var(--white); }
.tab-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--text-dim); flex-shrink: 0;
}
.tab-dot.dot-ok   { background: var(--ok); }
.tab-dot.dot-warn { background: var(--warn); }
.tab-dot.dot-err  { background: var(--err); }

.tab-content {
  flex: 1; overflow-y: auto; padding: 1.5rem;
  display: flex; flex-direction: column; gap: 1.25rem;
}

/* ── FORM FIELDS ─────────────────────────────────────────── */

.field-group { display: flex; flex-direction: column; gap: 0.4rem; }
.field-group label { font-size: 0.8rem; font-weight: 500; color: var(--text); }
.field-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

.inp {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text); font-family: var(--font-sans);
  font-size: 0.875rem; padding: 7px 10px; outline: none;
  transition: border-color 0.15s, background 0.15s; -webkit-appearance: none;
}
.inp:focus { border-color: var(--border-focus); background: var(--bg-3); }
.inp::placeholder { color: var(--text-dim); }
textarea.inp { resize: vertical; min-height: 72px; }
select.inp {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23555'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; padding-right: 28px;
}
select.level-informational { color: var(--lvl-informational); }
select.level-low            { color: var(--lvl-low); }
select.level-medium         { color: var(--lvl-medium); }
select.level-high           { color: var(--lvl-high); }
select.level-critical       { color: var(--lvl-critical); }

.inp-row { display: flex; gap: 0.4rem; }
.inp-row .inp { flex: 1; }
.list-row { display: flex; gap: 0.4rem; align-items: center; }
.separator { height: 1px; background: var(--border-soft); margin: 0.25rem 0; }

/* ── LOGSOURCE FIELD SUGGESTIONS ─────────────────────────── */

.field-suggestions {
  background: var(--bg-1); border: 1px solid var(--border-soft);
  border-radius: var(--r-md); padding: 0.75rem;
}
.field-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem; }
.chip {
  font-family: var(--font-mono); font-size: 0.65rem; padding: 2px 7px;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 3px;
  color: var(--text-muted);
}

/* ── DETECTION GROUPS ────────────────────────────────────── */

.detection-group {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem;
}
.group-header { display: flex; align-items: center; gap: 0.5rem; }
.group-name-inp { width: 140px; flex-shrink: 0; font-weight: 700; }
.group-type-toggle {
  display: flex; border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; flex-shrink: 0;
}
.btn-type {
  font-family: var(--font-mono); font-size: 0.65rem; letter-spacing: 0.04em;
  padding: 3px 10px; background: transparent; border: none;
  color: var(--text-muted); cursor: pointer; transition: background 0.15s, color 0.15s;
}
.btn-type.active { background: var(--bg-3); color: var(--text); }
.btn-type + .btn-type { border-left: 1px solid var(--border); }

.group-fields, .group-keywords { display: flex; flex-direction: column; gap: 0.75rem; }
.field-entry {
  background: var(--bg-2); border: 1px solid var(--border-soft);
  border-radius: var(--r-sm); padding: 0.75rem;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.field-entry-top { display: flex; gap: 0.4rem; align-items: center; }
.field-name-wrap { flex: 1; }
.field-name-inp { font-weight: 700; }
.modifier-sel { width: 180px; flex-shrink: 0; font-size: 0.75rem; }
.field-values {
  padding-left: 0.5rem; border-left: 2px solid var(--border);
  display: flex; flex-direction: column; gap: 0.35rem;
}
.value-row .inp { font-size: 0.8rem; }

/* ── CONDITION TEMPLATES ─────────────────────────────────── */

.condition-templates { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.btn-cond-tpl {
  font-family: var(--font-mono); font-size: 0.65rem;
  padding: 3px 9px; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text-muted); cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-cond-tpl:hover { color: var(--text); border-color: var(--border-focus); }
.btn-cond-tpl.active { background: var(--bg-2); color: var(--white); border-color: var(--white); }

/* ── TAGS TAB ────────────────────────────────────────────── */

.tags-tab {
  gap: 0.75rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}

.matrix-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  flex-shrink: 0;
}

.matrix-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.matrix-search-inp {
  width: 200px;
}

/* ── ATTACK MATRIX ───────────────────────────────────────── */

.attack-matrix-wrap {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  min-height: 0;
}

.attack-matrix {
  display: grid;
  grid-template-rows: auto 1fr;
  /* 14 tactic columns */
  grid-template-columns: repeat(14, minmax(148px, 1fr));
  min-width: 2072px;
}

/* Tactic header cells — row 1 */
.matrix-tactic-header {
  grid-row: 1;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  z-index: 2;
}
.matrix-tactic-header:last-child { border-right: none; }

.tactic-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tactic-count {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--text-muted);
}

/* Technique columns — row 2 */
.matrix-column {
  grid-row: 2;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  align-content: start;
}
.matrix-column:last-child { border-right: none; }

/* Individual technique cells */
.matrix-cell {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
  transition: background 0.1s, border-color 0.1s;
  position: relative;
  user-select: none;
  touch-action: manipulation;   /* no 300ms tap delay on mobile */
  min-height: 44px;             /* iOS minimum tappable area */
}
.matrix-cell:hover {
  background: var(--bg-2);
  border-color: var(--border-focus);
}
.matrix-cell.selected {
  background: rgba(226,226,226,0.08);
  border-color: var(--white);
}
.matrix-cell.selected .cell-id { color: var(--white); }
.matrix-cell.search-miss {
  opacity: 0.2;
}
.matrix-cell.search-match {
  border-color: var(--info);
}
.matrix-cell.selected.search-match {
  border-color: var(--white);
}

/* Sub-technique cells */
.matrix-sub-cell {
  margin-left: 10px;
  background: var(--bg-2);
  border-color: var(--border-soft);
}
.matrix-sub-cell::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  width: 6px;
  height: 1px;
  background: var(--border);
}
.matrix-sub-cell:hover { background: var(--bg-3); }
.matrix-sub-cell.selected { background: rgba(226,226,226,0.06); border-color: var(--white); }

.cell-id {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}
.cell-name {
  font-size: 0.68rem;
  color: var(--text);
  line-height: 1.3;
}
.cell-sub-toggle {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--text-muted);
  margin-top: 2px;
  align-self: flex-end;
}

/* ── LIVE PREVIEW PANEL ──────────────────────────────────── */

.preview-panel {
  display: flex; flex-direction: column;
  background: var(--bg-1); overflow: hidden;
}
.preview-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.preview-panel-actions { display: flex; gap: 0.4rem; }
.lint-inline {
  padding: 0.5rem 1rem; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.25rem; flex-shrink: 0;
}
.lint-err-inline { font-family: var(--font-mono); font-size: 0.65rem; color: var(--err); }
.yaml-live {
  flex: 1; overflow-y: auto; padding: 1rem;
  font-family: var(--font-mono); font-size: 0.72rem; line-height: 1.6;
  color: var(--text); white-space: pre; tab-size: 2; background: var(--bg-1);
}

/* ── PREVIEW TAB ─────────────────────────────────────────── */

.preview-tab { gap: 1rem; }
.lint-box {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 0.75rem 1rem;
  display: flex; flex-direction: column; gap: 0.35rem;
}
.lint-box.lint-clean { color: var(--ok); font-family: var(--font-mono); font-size: 0.8rem; border-color: rgba(74,222,128,0.2); }
.lint-item { font-family: var(--font-mono); font-size: 0.75rem; }
.lint-error   { color: var(--err); }
.lint-warning { color: var(--warn); }
.preview-actions { display: flex; gap: 0.5rem; }
.yaml-preview {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 1rem; font-family: var(--font-mono); font-size: 0.72rem; line-height: 1.7;
  color: var(--text); white-space: pre; overflow-x: auto; tab-size: 2; flex: 1;
}

/* ── MODALS ──────────────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.modal {
  background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--r-lg);
  width: 100%; max-width: 560px; max-height: 85vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-import   { max-width: 700px; }
.modal-settings { max-width: 500px; }
.modal-browser  { max-width: 900px; height: 75vh; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-title-row { display: flex; align-items: baseline; gap: 1rem; }
.modal-title { font-weight: 600; font-size: 0.9rem; }
.modal-link { font-family: var(--font-mono); font-size: 0.65rem; color: var(--text-muted); }
.modal-link:hover { color: var(--text); }

.modal-body {
  padding: 1.25rem; overflow-y: auto;
  display: flex; flex-direction: column; gap: 1rem; flex: 1;
}
.modal-footer { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

/* ── COMMUNITY BROWSER ───────────────────────────────────── */

.browser-layout {
  display: grid; grid-template-columns: 220px 1fr;
  flex: 1; overflow: hidden;
}

.browser-sidebar {
  border-right: 1px solid var(--border); overflow-y: auto;
  padding: 0.75rem 0;
}
.browser-group { margin-bottom: 0.5rem; }
.browser-group-label {
  padding: 0.35rem 1rem; display: block;
  font-family: var(--font-mono); font-size: 0.6rem;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted);
}
.browser-cat-btn {
  display: block; width: 100%; text-align: left;
  padding: 0.4rem 1rem; background: transparent; border: none;
  font-family: var(--font-sans); font-size: 0.78rem; color: var(--text-muted);
  cursor: pointer; transition: background 0.1s, color 0.1s;
  border-left: 2px solid transparent;
}
.browser-cat-btn:hover { background: var(--bg-2); color: var(--text); }
.browser-cat-btn.active { color: var(--white); border-left-color: var(--white); background: var(--bg-2); }

.browser-files {
  display: flex; flex-direction: column; overflow: hidden;
}
.browser-files-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.browser-search { flex: 1; }

.browser-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 0.5rem; padding: 2rem; text-align: center;
  color: var(--text-muted); font-size: 0.85rem;
}

.browser-status {
  padding: 1rem; font-family: var(--font-mono); font-size: 0.75rem;
  color: var(--text-muted);
}
.browser-status.err { color: var(--err); }

.browser-file-list {
  flex: 1; overflow-y: auto; padding: 0.5rem;
  display: flex; flex-direction: column; gap: 2px;
}
.browser-file-btn {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.45rem 0.75rem; background: transparent; border: 1px solid transparent;
  border-radius: var(--r-sm); cursor: pointer; text-align: left;
  transition: background 0.1s, border-color 0.1s; width: 100%;
}
.browser-file-btn:hover { background: var(--bg-2); border-color: var(--border); }
.browser-file-btn:disabled { opacity: 0.5; cursor: wait; }
.browser-file-name {
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.browser-file-arrow { font-size: 0.75rem; color: var(--text-muted); flex-shrink: 0; margin-left: 0.5rem; }

/* ── LOCAL TEMPLATES MODAL ───────────────────────────────── */

.tpl-list { display: flex; flex-direction: column; gap: 0.3rem; }
.tpl-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 0.9rem; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); cursor: pointer; color: var(--text);
  font-family: var(--font-sans); font-size: 0.8rem;
  transition: background 0.12s, border-color 0.12s; text-align: left; width: 100%;
}
.tpl-card:hover { background: var(--bg-3); border-color: var(--border-focus); }
.tpl-card:disabled { opacity: 0.5; cursor: wait; }
.tpl-name { flex: 1; }
.tpl-arrow { color: var(--text-muted); font-size: 0.8rem; }

/* ── IMPORT MODAL ────────────────────────────────────────── */

.yaml-import-area {
  min-height: 300px; resize: vertical;
  font-family: var(--font-mono); font-size: 0.75rem; line-height: 1.6;
}

/* ── TOAST ───────────────────────────────────────────────── */

.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 300;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 0.5rem 1rem; font-family: var(--font-mono); font-size: 0.75rem; color: var(--ok);
  pointer-events: none; opacity: 0; transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.visible { opacity: 1; transform: translateY(0); }

/* ── FOOTER ──────────────────────────────────────────────── */

.footer { border-top: 1px solid var(--border-soft); padding: 0.75rem 1.5rem; }
.footer-inner {
  max-width: 1600px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center;
}
.footer-inner span { font-size: 0.7rem; color: var(--text-muted); }
.footer-inner a { color: var(--text-muted); }
.footer-inner a:hover { color: var(--text); }

/* ── RESPONSIVE ──────────────────────────────────────────── */

/* ---- Tablet (≤ 1024px) already hides preview panel ---- */
@media (max-width: 1024px) {
  .builder-layout {
    /* use dynamic viewport height when available so mobile chrome bars don't cut content */
    height: calc(100dvh - var(--nav-h) - var(--toolbar-h) - 48px);
  }
}

/* ---- Narrow desktop / laptop toolbar wraps into two rows ---- */
@media (max-width: 1380px) {
  :root {
    --toolbar-h: 88px;
  }

  .toolbar {
    height: auto;
  }

  .toolbar-inner {
    flex-wrap: wrap;
    align-items: center;
    row-gap: 0.5rem;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .toolbar-left {
    flex-shrink: 0;
  }

  .toolbar-tabs {
    flex: 1 1 auto;
    min-width: 420px;
    justify-content: flex-start;
    height: 44px;
  }

  .toolbar-right {
    flex: 0 0 100%;
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
  }
}

/* ---- Mobile (≤ 768px) ---- */
@media (max-width: 768px) {
  /* ─ Variables ─ */
  :root {
    --nav-h:     44px;
    --toolbar-h: 168px;
  }

  /* ─ Nav ─ */
  .nav-inner { padding: 0 1rem; }
  .nav-links { display: none; }        /* hide github link — saves space */

  /* ─ Toolbar: mobile stacked layout ─
     Row 1: title + status
     Row 2: tabs
     Row 3-4: action buttons in two wrapped rows */
  .toolbar {
    height: auto;
    flex-direction: column;
  }
  .toolbar-inner {
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    gap: 0;
  }
  /* Row 1 */
  .toolbar-left {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0 0.75rem; height: 44px; flex-shrink: 0;
  }
  .toolbar-right {
    width: 100%;
    margin-left: 0;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .toolbar-right .btn-tool { display: flex; }
  /* Row 1: community, templates, library, import, share */
  .toolbar-right .btn-tool:nth-child(1),
  .toolbar-right .btn-tool:nth-child(2),
  .toolbar-right .btn-tool:nth-child(3),
  .toolbar-right .btn-tool:nth-child(5),
  .toolbar-right .btn-tool:nth-child(6) { order: 1; }
  /* Row 2: save, new, settings, export */
  .toolbar-right .btn-tool:nth-child(4),
  .toolbar-right .btn-tool:nth-child(7),
  .toolbar-right .btn-tool:nth-child(8),
  .toolbar-right .btn-tool:nth-child(9) { order: 2; }

  /* Tabs row — full width, horizontally scrollable */
  .toolbar-tabs {
    flex: none;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid var(--border);
    justify-content: flex-start;
    height: 44px;
  }
  .toolbar-tabs::-webkit-scrollbar { display: none; }
  .toolbar-tabs .tab-btn {
    padding: 0 0.85rem;
    font-size: 0.65rem;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ─ Builder layout ─ */
  .builder-layout {
    height: calc(100dvh - var(--nav-h) - var(--toolbar-h) - 48px);
    min-height: 0;
  }
  .builder-layout.matrix-mode {
    height: calc(100dvh - var(--nav-h) - var(--toolbar-h) - 48px);
  }
  .preview-panel { display: none; }     /* already hidden at 1024 but reaffirm */

  /* ─ Form padding ─ */
  .tab-content { padding: 1rem 0.875rem; }

  /* ─ Field rows: always single column ─ */
  .field-row { grid-template-columns: 1fr; }

  /* ─ Detection: stack field-name + modifier + × vertically ─ */
  .field-entry-top {
    flex-wrap: wrap;
    gap: 0.35rem;
  }
  .field-name-wrap { width: 100%; flex: none; order: 1; }
  .modifier-sel    { flex: 1; min-width: 0; order: 2; }
  .field-entry-top .btn-icon { order: 3; flex-shrink: 0; }

  /* ─ Group header: wrap name + type toggle ─ */
  .group-header { flex-wrap: wrap; }
  .group-name-inp { flex: 1; min-width: 80px; }

  /* ─ Matrix: make cells touch-friendlier ─ */
  .matrix-cell { padding: 6px 8px; }
  .cell-name   { font-size: 0.72rem; }
  .cell-id     { font-size: 0.6rem; }
  .matrix-search-inp { width: 100%; }
  .matrix-header { gap: 0.35rem; }
  .matrix-controls { width: 100%; }

  /* ─ Modals: full-screen-ish ─ */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;      /* sheet slides up from bottom */
  }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 92dvh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: none;
  }
  .modal-browser { height: 90dvh; }
  .modal-wizard  { max-width: 100%; }

  /* ─ Browser layout ─ */
  .browser-layout  { grid-template-columns: 1fr; }
  .browser-sidebar { display: none; }

  /* ─ Misc ─ */
  .btn-tool { padding: 4px 8px; font-size: 0.65rem; }
  .preview-actions { flex-wrap: wrap; }
  .ai-actions      { flex-wrap: wrap; }

  /* ─ iOS auto-zoom prevention — inputs must be ≥ 16px font-size ─ */
  .inp, select.inp, textarea.inp { font-size: 16px; }
}

/* ── CONTEXT MENU ────────────────────────────────────────── */

.ctx-overlay {
  position: fixed; inset: 0; z-index: 9998;
}
.ctx-menu {
  position: fixed; z-index: 9999;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 4px; min-width: 210px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.55), 0 2px 8px rgba(0,0,0,0.3);
  animation: ctx-pop 0.1s ease;
}
@keyframes ctx-pop {
  from { opacity: 0; transform: scale(0.95) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.ctx-item {
  display: block; width: 100%; text-align: left; padding: 6px 10px;
  background: transparent; border: none; border-radius: var(--r-sm);
  font-family: var(--font-sans); font-size: 0.78rem; color: var(--text);
  cursor: pointer; white-space: nowrap; transition: background 0.1s;
}
.ctx-item:hover { background: var(--bg-3); }
.ctx-item.disabled { color: var(--text-muted); cursor: default; }
.ctx-item.disabled:hover { background: transparent; }
.ctx-separator { height: 1px; background: var(--border); margin: 4px 0; }
.ctx-label {
  display: block; padding: 4px 10px 2px;
  font-family: var(--font-mono); font-size: 0.6rem;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted);
}

/* ── AI AUGMENTATION ─────────────────────────────────────── */

.btn-ai { color: var(--warn); border-color: rgba(250,204,21,0.25); }
.btn-ai:hover { border-color: var(--warn); background: rgba(250,204,21,0.06); }
.btn-ai.loading {
  opacity: 0.9;
  animation: ai-pulse 1s ease-in-out infinite;
}

@keyframes ai-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.ai-inline-panel {
  background: var(--bg-2); border: 1px solid rgba(250,204,21,0.2);
  border-radius: var(--r-md); padding: 0.75rem;
  display: flex; flex-direction: column; gap: 0.6rem;
  animation: ai-slide-in 0.2s ease;
}
@keyframes ai-slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-tag-suggest {
  background: var(--bg-2); border: 1px solid rgba(250,204,21,0.2);
  border-radius: var(--r-md); padding: 0.75rem;
  display: flex; flex-direction: column; gap: 0.6rem;
}
.ai-explain-panel { max-height: 400px; overflow-y: auto; }
.ai-review-panel  { max-height: 600px; overflow-y: auto; }

.ai-panel-header {
  display: flex; align-items: center; justify-content: space-between;
}

.ai-streaming-text {
  font-size: 0.82rem; color: var(--text); line-height: 1.6;
  white-space: pre-wrap; font-family: var(--font-sans);
}
.ai-streaming-text.streaming::after {
  content: '▋'; animation: blink 0.8s step-end infinite; color: var(--warn);
}
@keyframes blink { 50% { opacity: 0; } }

.ai-markdown-text {
  font-size: 0.82rem; line-height: 1.7; color: var(--text);
}
.ai-markdown-text h3, .ai-markdown-text h4 {
  font-size: 0.82rem; font-weight: 600; margin: 0.5rem 0 0.25rem; color: var(--white);
}
.ai-markdown-text p  { margin: 0.35rem 0; }
.ai-markdown-text li { margin: 0.2rem 0 0.2rem 1rem; list-style: disc; }
.ai-markdown-text code {
  font-family: var(--font-mono); font-size: 0.72rem;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 4px;
}
.ai-markdown-text strong { color: var(--white); font-weight: 600; }

.ai-error  { font-size: 0.78rem; color: var(--err); }
.ai-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.ai-tag-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.ai-tag-chip {
  font-family: var(--font-mono); font-size: 0.68rem; padding: 3px 9px;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-muted); cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.ai-tag-chip:hover  { color: var(--text); border-color: var(--border-focus); }
.ai-tag-chip.accepted { color: var(--ok); border-color: rgba(74,222,128,0.4); background: rgba(74,222,128,0.05); }

.ai-fp-list { display: flex; flex-direction: column; gap: 0.35rem; }
.ai-fp-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 0.4rem 0.6rem;
  font-size: 0.8rem; gap: 0.5rem;
}

/* description suggestion items are a bit taller since text wraps */
.ai-desc-item { align-items: flex-start; }
.ai-desc-item span { line-height: 1.5; flex: 1; }

/* detection ai bar */
.detection-ai-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.5rem;
}

/* detection ai panel */
.ai-detection-panel { margin-top: 0.75rem; }
.ai-detection-summary {
  font-size: 0.8rem; color: var(--text-muted); margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem; background: var(--bg-3); border-radius: var(--r-sm);
  border-left: 2px solid #60a5fa;
}
.ai-det-section { margin-bottom: 0.75rem; }
.ai-det-section-label {
  display: block; margin-bottom: 0.35rem;
  color: var(--text-muted); letter-spacing: 0.06em;
}
.ai-det-group {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 0.5rem 0.75rem; margin-bottom: 0.35rem;
}
.ai-det-group-header {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.4rem; flex-wrap: wrap;
}
.ai-det-name {
  font-family: var(--font-mono); font-size: 0.75rem;
  color: #4ade80; background: rgba(74,222,128,0.08);
  border: 1px solid rgba(74,222,128,0.2); border-radius: 3px; padding: 1px 6px;
}
/* filter groups use yellow accent */
.ai-det-section:nth-of-type(2) .ai-det-name {
  color: #facc15; background: rgba(250,204,21,0.08);
  border-color: rgba(250,204,21,0.2);
}
.ai-det-rationale { font-size: 0.75rem; color: var(--text-muted); flex: 1; }
.ai-det-fields { display: flex; flex-direction: column; gap: 0.2rem; }
.ai-det-field {
  display: flex; align-items: baseline; gap: 0.5rem;
  font-size: 0.75rem; padding: 0.15rem 0;
}
.ai-det-field code {
  font-family: var(--font-mono); font-size: 0.72rem;
  color: #93c5fd; white-space: nowrap;
}
.ai-det-values {
  color: var(--text-muted); font-family: var(--font-mono); font-size: 0.7rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px;
}
.ai-det-note { color: var(--text-dim); font-size: 0.7rem; font-style: italic; }
.ai-det-condition {
  display: flex; align-items: center; gap: 0.5rem;
  background: rgba(96,165,250,0.07); border: 1px solid rgba(96,165,250,0.2);
  border-radius: var(--r-sm); padding: 0.4rem 0.75rem; margin-bottom: 0.5rem;
}
.ai-det-condition .mono { margin-right: 0.25rem; color: var(--text-muted); }
.ai-det-condition code {
  font-family: var(--font-mono); font-size: 0.78rem; color: #93c5fd; flex: 1;
}

.ai-test-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.ai-test-result { font-family: var(--font-mono); font-size: 0.72rem; }
.ai-test-result.ok  { color: var(--ok); }
.ai-test-result.err { color: var(--err); }

/* ── Settings modal — AI section ─────────────────────────── */
.settings-section-head {
  display: flex; align-items: baseline; gap: 0.75rem;
  font-size: 0.8rem; font-weight: 600; color: var(--text);
  padding-bottom: 0.5rem; border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.settings-section-head .hint { font-weight: 400; color: var(--text-muted); font-size: 0.72rem; }

.endpoint-row {
  display: flex; align-items: center; gap: 0.4rem;
}
.endpoint-inp { flex: 1; }

.proto-toggle {
  display: flex; border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; flex-shrink: 0;
}
.btn-proto {
  font-family: var(--font-mono); font-size: 0.65rem; padding: 4px 8px;
  background: transparent; border: none; color: var(--text-muted); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-proto.active { background: var(--bg-3); color: var(--text); }
.btn-proto + .btn-proto { border-left: 1px solid var(--border); }

.ai-live-badge {
  font-family: var(--font-mono); font-size: 0.65rem;
  padding: 2px 8px; border-radius: 999px; border: 1px solid;
  white-space: nowrap; flex-shrink: 0; min-width: 24px; text-align: center;
  transition: all 0.2s;
}
.badge-ok      { color: var(--ok);   border-color: rgba(74,222,128,0.3);  background: rgba(74,222,128,0.07); }
.badge-err     { color: var(--err);  border-color: rgba(248,113,113,0.3); background: rgba(248,113,113,0.07); }
.badge-warn    { color: var(--warn); border-color: rgba(250,204,21,0.3);  background: rgba(250,204,21,0.07); }
.badge-testing { color: var(--text-muted); border-color: var(--border); background: transparent; animation: spin 1s linear infinite; }
.badge-idle    { color: var(--text-dim);   border-color: var(--border-soft); background: transparent; }

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

.model-row { display: flex; align-items: center; gap: 0.4rem; }
.model-row .inp { flex: 1; }
.model-row .btn-tool { flex-shrink: 0; }

.adv-toggle { font-size: 0.78rem; color: var(--text-muted); padding: 0.25rem 0; }
.adv-toggle:hover { color: var(--text); }
.adv-settings { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 0.6rem; }
.adv-row { display: flex; align-items: center; gap: 0.75rem; }
.adv-row label { font-size: 0.78rem; color: var(--text-muted); min-width: 130px; display: flex; gap: 0.4rem; align-items: center; }
.range-inp { flex: 1; accent-color: var(--text); }
.inp-sm { width: 90px; flex-shrink: 0; }

/* ── ANNOTATED YAML ──────────────────────────────────────── */

.yaml-annotated {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 1rem; font-family: var(--font-mono); font-size: 0.72rem;
  line-height: 1.7; white-space: pre; overflow-x: auto; tab-size: 2;
}
.yaml-seg { transition: background 0.15s; border-radius: 2px; }
.annot-error   { background: rgba(248,113,113,0.18); color: #fca5a5; box-shadow: 0 0 0 1px rgba(248,113,113,0.3); border-radius: 3px; cursor: help; }
.annot-warning { background: rgba(250,204,21,0.15);  color: #fde047; box-shadow: 0 0 0 1px rgba(250,204,21,0.3);  border-radius: 3px; cursor: help; }
.annot-info    { background: rgba(96,165,250,0.12);  color: #93c5fd; box-shadow: 0 0 0 1px rgba(96,165,250,0.25); border-radius: 3px; cursor: help; }
.annot-good    { background: rgba(74,222,128,0.12);  color: #86efac; box-shadow: 0 0 0 1px rgba(74,222,128,0.25); border-radius: 3px; cursor: help; }

.annot-legend {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.4rem 0.75rem; background: var(--bg-3);
  border: 1px solid var(--border); border-radius: var(--r-sm);
}
.legend-label { margin-right: 0.25rem; }
.legend-item { font-size: 0.72rem; cursor: default; }

.annot-list { display: flex; flex-direction: column; gap: 0.35rem; }
.annot-item {
  display: grid; grid-template-columns: 60px auto 1fr;
  align-items: start; gap: 0.5rem;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 0.4rem 0.6rem; font-size: 0.78rem;
}
.annot-badge {
  font-family: var(--font-mono); font-size: 0.58rem; letter-spacing: 0.05em;
  text-transform: uppercase; padding: 2px 6px; border-radius: 3px; text-align: center;
}
.annot-item-error   .annot-badge { background: rgba(248,113,113,0.15); color: #fca5a5; }
.annot-item-warning .annot-badge { background: rgba(250,204,21,0.15);  color: #fde047; }
.annot-item-info    .annot-badge { background: rgba(96,165,250,0.12);  color: #93c5fd; }
.annot-item-good    .annot-badge { background: rgba(74,222,128,0.12);  color: #86efac; }
.annot-target { font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-muted); }
.annot-note   { color: var(--text); line-height: 1.4; }

.review-score {
  font-family: var(--font-mono); font-size: 0.8rem; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; margin-left: auto;
}
.score-good { color: var(--ok);   background: rgba(74,222,128,0.1); }
.score-ok   { color: var(--warn); background: rgba(250,204,21,0.1); }
.score-low  { color: var(--err);  background: rgba(248,113,113,0.1); }

.review-summary {
  font-size: 0.82rem; color: var(--text); line-height: 1.6;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 0.6rem 0.75rem;
}

/* ── WIZARD MODAL ─────────────────────────────────────────── */

.modal-wizard { max-width: 680px; }

/* Wizard body: scrollable, fills available space between header and footer */
.wizard-body {
  gap: 0;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Step progress dots */
.wizard-steps {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 0.9rem;
}
.wizard-step-dot        { color: var(--text-dim); transition: color 0.15s; }
.wizard-step-dot.active { color: var(--white); }
.wizard-step-dot.done   { color: var(--ok); }

/* Scenario grid — 4 columns on desktop, responsive below */
.wizard-scenario-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem;
}
.wizard-scenario-card {
  display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
  padding: 0.75rem 0.5rem; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r-md); cursor: pointer; text-align: center;
  transition: background 0.15s, border-color 0.15s;
  touch-action: manipulation; min-height: 48px;
}
.wizard-scenario-card:hover  { background: var(--bg-3); border-color: var(--border-focus); }
.wizard-scenario-card.active { border-color: var(--white); background: rgba(226,226,226,0.06); }
.wizard-sc-icon  { font-size: 1.5rem; line-height: 1; }
.wizard-sc-label { font-size: 0.78rem; font-weight: 600; color: var(--white); }
.wizard-sc-desc  { font-size: 0.65rem; color: var(--text-muted); line-height: 1.3; }

/* Level pills */
.wizard-level-pills { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.wizard-level-pill {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.04em;
  padding: 5px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text-muted); cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  touch-action: manipulation;
}
.wizard-level-pill:hover { border-color: var(--border-focus); color: var(--text); }
.wizard-level-pill.active                    { color: var(--bg); border-color: transparent; }
.wizard-level-pill.pill-informational.active { background: var(--lvl-informational); }
.wizard-level-pill.pill-low.active           { background: var(--lvl-low); }
.wizard-level-pill.pill-medium.active        { background: var(--lvl-medium); }
.wizard-level-pill.pill-high.active          { background: var(--lvl-high); }
.wizard-level-pill.pill-critical.active      { background: var(--lvl-critical); }

/* Logsource list */
.wizard-ls-grid {
  display: flex; flex-direction: column; gap: 0.35rem;
}
.wizard-ls-card {
  display: flex; flex-direction: column; gap: 3px;
  padding: 0.65rem 0.9rem; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); cursor: pointer; text-align: left;
  transition: background 0.12s, border-color 0.12s; width: 100%;
  touch-action: manipulation;
}
.wizard-ls-card:hover  { background: var(--bg-3); border-color: var(--border-focus); }
.wizard-ls-card.active { border-color: var(--white); background: rgba(226,226,226,0.06); }
.wizard-ls-label { font-size: 0.8rem; font-weight: 600; color: var(--white); }
.wizard-ls-meta  { font-family: var(--font-mono); font-size: 0.65rem; color: var(--text-muted); }

/* YAML review preview */
.wizard-yaml-preview {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 1rem; font-family: var(--font-mono); font-size: 0.7rem; line-height: 1.7;
  color: var(--text); white-space: pre; overflow-x: auto; tab-size: 2;
  overflow-y: auto;
}

/* Footer: cancel left, back+next right */
.wizard-footer {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  justify-content: space-between;
  flex-shrink: 0;    /* never squish the footer */
}

/* ── WIZARD MOBILE OVERRIDES ─── */
@media (max-width: 768px) {
  /* Scenario: 2 columns, hide desc text to save vertical space */
  .wizard-scenario-grid { grid-template-columns: 1fr 1fr; gap: 0.4rem; }
  .wizard-scenario-card { padding: 0.6rem 0.4rem; gap: 0.25rem; }
  .wizard-sc-desc  { display: none; }   /* too much text in 2-col layout */
  .wizard-sc-label { font-size: 0.72rem; }
  .wizard-sc-icon  { font-size: 1.25rem; }

  /* Level pills: stretch to fill row */
  .wizard-level-pills { gap: 0.3rem; }
  .wizard-level-pill  { flex: 1; text-align: center; padding: 7px 4px; min-width: 0; }

  /* Logsource: slightly less padding */
  .wizard-ls-card { padding: 0.55rem 0.75rem; }

  /* YAML preview: don't let it grow infinitely — modal body scrolls instead */
  .wizard-yaml-preview { font-size: 0.65rem; }

  /* Footer buttons: stack only if truly too narrow, otherwise side-by-side */
  .wizard-footer { gap: 0.5rem; }
}

/* ── RULE LIBRARY MODAL ──────────────────────────────────── */
.modal-library { max-width: 640px; }

.lib-empty { text-align: center; padding: 2rem 1rem; color: var(--text-muted); }

.lib-list { display: flex; flex-direction: column; gap: 0.5rem; }

.lib-entry {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 0.75rem 1rem;
  display: flex; flex-direction: column; gap: 0.35rem;
  transition: border-color 0.15s;
}
.lib-entry:hover { border-color: var(--border-focus); }

.lib-entry-header {
  display: flex; align-items: center; gap: 0.6rem;
  cursor: pointer;
}
.lib-title {
  font-size: 0.875rem; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lib-level-badge {
  font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.05em;
  text-transform: uppercase; padding: 2px 7px; border-radius: 999px;
  border: 1px solid; flex-shrink: 0;
  color: var(--lc); border-color: var(--lc); background: transparent;
  filter: opacity(0.9);
}
.lib-entry-meta {
  display: flex; gap: 0.75rem; flex-wrap: wrap;
}
.lib-entry-meta .hint { font-size: 0.72rem; color: var(--text-muted); }
.lib-date { margin-left: auto; }

.lib-entry-actions {
  display: flex; gap: 0.4rem; margin-top: 0.25rem;
}
.btn-tool.small { padding: 2px 8px; font-size: 0.65rem; }
.btn-tool.danger { color: var(--err); border-color: rgba(248,113,113,0.2); }
.btn-tool.danger:hover { background: rgba(248,113,113,0.08); border-color: var(--err); }

@media (max-width: 768px) {
  .modal-library { max-width: 100%; }
}

/* ── QUERY CONVERTER ─────────────────────────────────────── */
.converter-panel {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 0.75rem 1rem;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.converter-header {
  display: flex; align-items: center; justify-content: space-between;
}
.converter-tabs { display: flex; gap: 0.4rem; }
.btn-conv-tab {
  font-family: var(--font-mono); font-size: 0.65rem; letter-spacing: 0.06em;
  padding: 3px 10px; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text-muted); cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-conv-tab:hover { color: var(--text); border-color: var(--border-focus); }
.btn-conv-tab.active { background: var(--bg-1); color: var(--white); border-color: var(--white); }

.converter-output-wrap {
  position: relative;
}
.converter-output {
  background: var(--bg-1); border: 1px solid var(--border-soft);
  border-radius: var(--r-sm); padding: 0.75rem 2.5rem 0.75rem 0.75rem;
  font-family: var(--font-mono); font-size: 0.72rem; line-height: 1.6;
  color: var(--text); white-space: pre-wrap; word-break: break-all;
  max-height: 300px; overflow-y: auto;
}
.btn-copy-conv {
  position: absolute; top: 0.4rem; right: 0.4rem;
  font-family: var(--font-mono); font-size: 0.6rem;
  padding: 2px 8px; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text-muted); cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.btn-copy-conv:hover { color: var(--text); border-color: var(--border-focus); }
.converter-note {
  font-size: 0.75rem; color: var(--warn); margin: 0;
}
