/* Windows 11 fluent shell. Light mica canvas, Segoe, 4px controls, 8px cards. */

:root {
  --accent: #0067c0;
  --accent-hover: #005a9e;
  --accent-pressed: #004c87;
  --accent-soft: #cde4f7;
  --text: #1a1a1a;
  --text-2: #5c5c5c;
  --text-3: #717171;
  --stroke: #e5e5e5;
  --stroke-strong: #d1d1d1;
  --control: #8a8a8a;
  --canvas: #f3f3f3;
  --nav: #f9f9f9;
  --card: #ffffff;
  --hover: rgba(0, 0, 0, 0.04);
  --pressed: rgba(0, 0, 0, 0.07);
  --selected: #e5e5e5;
  --ok: #0f7b0f;
  --ok-bg: #dff6dd;
  --warn: #9d5d00;
  --warn-bg: #fff4ce;
  --bad: #c42b1c;
  --bad-bg: #fde7e9;
  --radius: 8px;
  --radius-sm: 4px;
  --nav-w: 280px;
  --font: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", "Cascadia Code", ui-monospace, monospace;
  --shadow-dialog: 0 8px 16px rgba(0, 0, 0, 0.14);
  --focus: 0 0 0 2px #fff, 0 0 0 4px var(--accent);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
code { font-family: var(--mono); font-size: 0.92em; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-2); font-size: 12px; }

:focus-visible { outline: none; box-shadow: var(--focus); }

/* —— Controls —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 32px;
  width: max-content;
  max-width: 100%;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke-strong);
  background: var(--card);
  color: var(--text);
  font-weight: 400;
  white-space: nowrap;
  line-height: 1;
  flex: 0 0 auto;
}
.btn svg { width: 16px; height: 16px; flex: 0 0 16px; }
.btn:hover { background: #f6f6f6; }
.btn:active { background: #ededed; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-pressed); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--hover); }
.btn-danger {
  background: var(--bad);
  border-color: transparent;
  color: #fff;
}
.btn-danger:hover { background: #a4262c; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-icon { padding: 0 10px; }

.copy-btn.is-copied { color: var(--ok); border-color: var(--ok); }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--control);
  border-radius: var(--radius-sm);
  background: var(--card);
  padding: 5px 10px;
  min-height: 32px;
}
textarea { min-height: 96px; resize: vertical; padding: 8px 10px; }
input:hover, textarea:hover, select:hover { border-color: #616161; }
input:not([type="checkbox"]):focus,
textarea:focus,
select:focus,
input:not([type="checkbox"]):focus-visible,
textarea:focus-visible,
select:focus-visible {
  background: #fff;
  border-color: var(--accent);
  outline: none;
  box-shadow: none;
}
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:focus-visible,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
  transition: background-color 99999s ease-out 0s;
  box-shadow: 0 0 0 1000px #fff inset;
}
input:disabled, textarea:disabled, select:disabled { background: #f5f5f5; color: var(--text-3); }

input[type="checkbox"] {
  appearance: none;
  width: 40px;
  min-height: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: #8a8a8a;
  position: relative;
  flex: 0 0 auto;
  box-shadow: none;
}
input[type="checkbox"]::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  top: 4px;
  left: 4px;
  transition: left 0.12s ease;
}
input[type="checkbox"]:checked { background: var(--accent); }
input[type="checkbox"]:checked::after { left: 24px; }
input[type="checkbox"]:focus,
input[type="checkbox"]:focus-visible {
  outline: none;
  border: 0;
  background: #8a8a8a;
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--accent);
}
input[type="checkbox"]:checked:focus,
input[type="checkbox"]:checked:focus-visible {
  background: var(--accent);
}

/* —— Form system ——
   One pattern for every screen: label above the control, help text below it,
   one 16px gap between fields in a group, and one row of actions at the end.
   Booleans are a switch with its text beside it (.check-line / .check-field). */
:root { --field-gap: 16px; --field-stack: 6px; --control-h: 32px; }

/* Every form is a grid, so the same gap separates fields, notes and the action row. */
form { display: grid; gap: var(--field-gap); min-width: 0; }
label { display: grid; gap: var(--field-stack); min-width: 0; }
.field { display: grid; gap: var(--field-stack); min-width: 0; align-content: start; }
.field-label {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-2);
  min-width: 0;
  overflow-wrap: anywhere;
}
.field:has([required]) > .field-label::after { content: " *"; color: var(--bad); }
.field-help, .config-help, .form-note {
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-3);
  min-width: 0;
  overflow-wrap: anywhere;
}
.form-note { margin: 0; }

.check-line {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--control-h);
  min-width: 0;
}
.check-line > span { font-size: 14px; color: var(--text); min-width: 0; }
.check-field { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.check-field > .check-field-text { display: grid; gap: 2px; min-width: 0; }
.check-field-text > .config-field-head { font-size: 14px; font-weight: 400; color: var(--text); }
.check-group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 24px; min-height: var(--control-h); }

.form-grid, .config-grid { display: grid; gap: var(--field-gap); min-width: 0; }
.form-grid > *, .field-row > * { min-width: 0; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--field-gap); align-items: start; min-width: 0; }
.form-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: var(--field-gap); align-items: start; min-width: 0; }
.actions, .config-actions, .dialog-actions, .form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }

.alert {
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid transparent;
}
.alert-error { background: var(--bad-bg); color: #6b1210; border-color: #f1bbbc; }
.alert-ok { background: var(--ok-bg); color: #0b5a0b; border-color: #9fd89f; }

.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 10px;
  font-size: 12px;
  background: #ebebeb;
  color: var(--text);
  white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-muted { background: #ebebeb; color: var(--text-2); }

/* —— Sign-in —— */
.security-check {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 50% -10%, #e8f2fb, transparent 60%),
    var(--canvas);
}
.security-guard {
  width: 56px;
  height: 56px;
  color: var(--accent);
}
.security-guard svg { width: 56px; height: 56px; display: block; }
.security-check p {
  margin: 0;
  color: var(--text-2);
  font-size: 14px;
}
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 50% -10%, #e8f2fb, transparent 60%),
    var(--canvas);
}
.login-panel {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  padding: 28px 28px 24px;
}
.login-brand-mark {
  width: 40px;
  height: 40px;
  color: var(--accent);
  margin-bottom: 12px;
}
.login-brand-mark svg { width: 40px; height: 40px; }
.login-panel h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }
.login-copy { color: var(--text-2); margin: 6px 0 18px; }
.login-form { gap: 12px; }

/* —— Shell —— */
.app-shell { min-height: 100vh; display: flex; background: var(--canvas); }
.sidebar {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  display: flex;
  flex-direction: column;
  background: var(--nav);
  border-right: 1px solid var(--stroke);
  padding: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 14px 10px 18px; }
.brand-badge { display: none; }
.brand-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
}
.brand-title span { font-weight: 700; }
.brand-caption { display: none; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; overflow: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
  white-space: nowrap;
  flex: 0 0 auto;
}
.nav-item span { min-width: 0; }
.nav-item svg { width: 16px; height: 16px; flex: 0 0 16px; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--selected); font-weight: 600; }
.nav-training-spin { margin-left: auto; animation: spin 1.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.sidebar-foot { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--stroke); }
.user-card { display: flex; align-items: center; gap: 10px; padding: 10px 8px; }
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.user-avatar svg { width: 18px; height: 18px; }
.user-meta { min-width: 0; flex: 1; }
.user-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-email { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px 6px; }
.sidebar-actions .btn { flex: 0 0 auto; }

.workspace { flex: 1; min-width: 0; max-width: 100%; display: flex; flex-direction: column; }
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 28px 36px 8px;
  min-width: 0;
}
.eyebrow { font-size: 12px; color: var(--text-3); margin-bottom: 2px; }
.page-header h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }
.page-header > div:first-child { min-width: 0; }
.page-desc { color: var(--text-2); margin-top: 4px; max-width: 62ch; }
.header-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  max-width: 100%;
  padding: 0 10px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--stroke);
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  flex: 0 1 auto;
}
.header-chip span:last-child { overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.content { padding: 12px 36px 40px; display: grid; gap: 12px; min-width: 0; }

.view { display: grid; gap: 12px; min-width: 0; }
.surface, .overview-tile, .kpi, .info-band, .train-status-hero, .progress-block, .secret-box {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
}
.surface { padding: 4px 16px 16px; }
.surface-head, .siem-head, .code-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 0 10px;
}
.surface-head > div, .siem-head > div, .code-head > div { min-width: 0; flex: 1 1 160px; }
.surface-head h2, .siem-head h3 { font-size: 16px; font-weight: 600; }
.surface-head p, .config-banner p { color: var(--text-2); font-size: 13px; margin-top: 2px; }

/* Overview */
.overview-hero, .overview-metrics, .kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
  gap: 12px;
  min-width: 0;
}
.overview-tile, .kpi { padding: 14px 16px; min-width: 0; overflow: hidden; }
.overview-icon, .overview-kicker, .info-band-icon { display: none; }
.overview-tile-top { display: none; }
.overview-label, .kpi-label, .train-status-label, .secret-label, .integrate-fact-k {
  font-size: 12px;
  color: var(--text-2);
}
.overview-value, .kpi-value, .train-phase { font-size: 20px; font-weight: 600; margin-top: 4px; overflow-wrap: anywhere; }
.overview-value-lg { font-size: 22px; }
.overview-hint { color: var(--text-3); font-size: 12px; margin-top: 6px; }
.overview-section-label { font-size: 12px; font-weight: 600; color: var(--text-2); margin-top: 4px; }
.info-band { display: block; padding: 14px 16px; }
.info-band h2 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.info-band p { color: var(--text-2); }

/* Training */
.train-status-hero { display: flex; justify-content: space-between; gap: 16px; padding: 16px; }
.train-detail, .train-meta { color: var(--text-2); margin-top: 4px; }
.train-status-side { text-align: right; }
.train-loop-actions { padding-top: 0; }
#train-loop-state { margin: 0 0 4px; }
.progress-block { padding: 12px 16px; }
.progress-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.progress-track { height: 4px; background: #e6e6e6; border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 2px; }
.train-log, .code-block, #token-secret {
  margin: 0;
  background: #fafafa;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  overflow: auto;
  max-height: 280px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 12px;
}

/* Config */
.config-banner { padding: 0 2px; }
.config-meta { margin-top: 6px; }
#config-form { min-width: 0; }
.config-tabs {
  display: flex;
  gap: 2px;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--stroke);
}
.config-tab {
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--text-2);
  white-space: nowrap;
  width: max-content;
  flex: 0 0 auto;
  line-height: 1;
}
.config-tab:hover { background: var(--hover); color: var(--text); }
.config-tab[aria-selected="true"] {
  color: var(--accent);
  font-weight: 600;
  border-bottom-color: var(--accent);
}
.config-panel-desc { color: var(--text-2); font-size: 13px; padding: 12px 0 4px; }
.config-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr));
  gap: 0 32px;
  align-items: start;
}
.config-field { display: grid; gap: var(--field-stack); align-content: start; min-width: 0; padding: 14px 0; border-top: 1px solid var(--stroke); }
.config-field.check-field { display: flex; }
.config-field-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-width: 0; }
.config-badge { font-size: 11px; font-weight: 400; color: var(--text-2); background: #f3f3f3; border-radius: 10px; padding: 1px 8px; white-space: nowrap; }
.config-badge-now { background: var(--accent-soft); color: var(--accent); }
.config-badge-later { background: var(--warn-bg); color: var(--warn); }
.config-field.is-overridden .config-field-head { font-weight: 700; color: var(--text); }
#config-area-tabs { margin-bottom: 12px; }
.config-area { display: grid; gap: 12px; min-width: 0; }
.td-sub { display: grid; gap: 12px; min-width: 0; }
#td-sub-tabs { margin: 0; }
.td-form-grid { grid-template-columns: minmax(0, 2fr) repeat(2, minmax(80px, 1fr)); }
.os-job-grid, .os-job-map-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.os-job-query { display: grid; gap: var(--field-stack); }
.os-job-mapping { display: grid; gap: var(--field-gap); min-width: 0; margin: 0; padding: 0; border: 0; }
.os-job-mapping > legend { padding: 0; margin-bottom: 4px; font-size: 14px; font-weight: 600; color: var(--text); }
.os-job-mapping > legend::after { content: none; }
#os-job-form.surface { display: grid; gap: var(--field-gap); padding: 14px 16px 16px; }
#td-kpi-index { font-size: 16px; }
.package-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.package-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: var(--card);
  min-width: 0;
}
.package-card.is-active { border-color: var(--accent); background: var(--accent-soft); }
.package-card h3 { font-size: 14px; font-weight: 600; }
.package-card p { color: var(--text-2); font-size: 12px; }
.package-card .config-actions { padding-top: 0; }
.package-save {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  margin-top: 12px;
}
.package-save label { flex: 1 1 220px; min-width: 0; }

/* Tables */
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--stroke); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--text-2); }
tbody tr:hover td { background: #f8f8f8; }
.col-actions, .tokens-table td:last-child, .history-table td:last-child { text-align: right; }
.row-actions { display: inline-flex; gap: 6px; }
.history-pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 10px;
  color: var(--text-2);
  font-size: 12px;
}
.history-pager-controls, .history-size { display: flex; align-items: center; gap: 8px; }
.history-size select { width: auto; min-height: var(--control-h); height: var(--control-h); }

.empty-state { text-align: center; color: var(--text-2); padding: 28px 12px; }
.empty-state svg { width: 28px; height: 28px; color: var(--text-3); }
.empty-state p { margin-top: 8px; }

/* Tokens */
.secret-box { padding: 12px; margin-bottom: 12px; display: grid; gap: 8px; }
.integrate-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; padding-bottom: 8px; }
.integrate-fact { display: grid; gap: 2px; }
.integrate-block { margin-top: 10px; }
.integrate-note { color: var(--text-2); font-size: 12px; margin-top: 8px; }

/* Live test */
.split { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 12px; align-items: start; min-width: 0; }
.predict-content { min-height: 180px; }
.lookup-form { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--stroke); }
.result-stack { display: grid; gap: 8px; }
.result-row { display: grid; grid-template-columns: minmax(88px, 110px) minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.result-v, .result-c { min-width: 0; overflow-wrap: anywhere; }
.result-k { color: var(--text-2); font-size: 12px; }
.result-v { font-weight: 600; }
.meter { grid-column: 1 / -1; height: 4px; background: #ececec; border-radius: 2px; overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; background: var(--accent); }
.kv { display: grid; grid-template-columns: minmax(0, 34%) minmax(0, 1fr); gap: 4px 12px; margin: 0; }
.kv dt { color: var(--text-2); font-size: 12px; }
.kv dd { margin: 0; word-break: break-word; }
.kv-empty { color: var(--text-3); }
.siem-block { border-top: 1px solid var(--stroke); padding-top: 4px; }
.clean-text summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
.dash-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}
.dash-toolbar .muted { min-width: 0; }
.dash-slicer { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.dash-slicer span { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.dash-slicer select { width: min(220px, 46vw); }
.ops-board-lead {
  margin: 0 0 10px;
  color: var(--text-2);
  font-size: 13px;
}
.ops-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}
.ops-stage {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
  padding: 14px 16px 16px;
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  border-top: 3px solid var(--accent);
  box-shadow: 0 1.6px 3.6px rgba(0, 0, 0, 0.08), 0 0.3px 0.9px rgba(0, 0, 0, 0.06);
}
.ops-stage.is-alert { border-top-color: var(--bad); }
.ops-stage-head { min-width: 0; }
.ops-stage-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.ops-stage.is-alert .ops-stage-kicker { color: var(--bad); }
.ops-stage-head h3 { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.ops-stage-head p { margin-top: 4px; color: var(--text-2); font-size: 12px; }
.ops-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 12px;
}
.ops-metric { min-width: 0; }
.ops-metric-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  overflow-wrap: anywhere;
}
.ops-metric.is-bad .ops-metric-value { color: var(--bad); }
.ops-metric-label { margin-top: 4px; font-size: 12px; font-weight: 600; }
.ops-metric-why { margin-top: 2px; font-size: 11px; color: var(--text-3); }
.ops-formats { padding-top: 4px; border-top: 1px solid var(--stroke); }
.ops-formats h4 { font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.format-bars { display: grid; gap: 8px; margin-top: 8px; }
.format-bar { display: grid; grid-template-columns: minmax(72px, 140px) minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.format-bar span { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.format-bar i { display: block; height: 8px; background: #e8eef5; border-radius: 4px; overflow: hidden; }
.format-bar b { display: block; height: 100%; background: #118dff; border-radius: 4px; }
.format-bar strong { font-size: 12px; font-weight: 700; }
.stats-channels { display: grid; gap: 10px; }
.dash-report {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: 0 1.6px 3.6px rgba(0, 0, 0, 0.08), 0 0.3px 0.9px rgba(0, 0, 0, 0.06);
}
.dash-report-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; min-width: 0; }
.dash-report-head h3 { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }
.dash-report-head p { margin-top: 2px; color: var(--text-2); font-size: 12px; }
.avg-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 0; }
.avg-card { min-width: 0; padding: 6px 8px; border-radius: 6px; background: #f4f7fb; }
.avg-card span { display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-2); }
.avg-card strong { display: block; margin-top: 2px; font-size: 18px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.avg-card em { font-style: normal; font-size: 11px; color: var(--text-3); }
.dash-visuals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.dash-matrices { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 8px; }
.dash-visual {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: #fbfcfd;
}
.dash-visual-wide { grid-column: 1 / -1; }
.dash-visual h4, .chart-block h4 { margin: 0 0 4px; font-size: 13px; font-weight: 600; color: var(--text); }
.echart { width: 100%; height: 168px; }
.dash-visual-wide .echart { height: 210px; }
.chart-axis { font-size: 11px; fill: #717171; font-family: var(--font); }
.chart-compact .chart-axis { font-size: 13px; }
.chart-grid { stroke: #e6e6e6; stroke-width: 1; }
.chart-guide { stroke: #c19c00; stroke-width: 1.25; stroke-dasharray: 4 4; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 4px; font-size: 11px; color: var(--text-2); }
.chart-legend span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.status-pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
}
.status-normal { background: var(--ok-bg); color: var(--ok); }
.status-above { background: var(--warn-bg); color: var(--warn); }
.status-below { background: #deecf9; color: #0b4f8a; }
.status-na { background: #f3f3f3; color: var(--text-2); }
.matrix { display: grid; gap: 8px; min-width: 0; }
.matrix-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.matrix-tools input { flex: 1 1 140px; min-width: 120px; height: 32px; }
.matrix-tools select { flex: 1 1 128px; width: auto; min-width: 128px; height: 32px; }
.matrix-pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 12px;
}
.matrix-pager > span { white-space: nowrap; }
.matrix-pager-controls { display: flex; align-items: center; gap: 8px; }
.dash-visual th { background: #f3f6f9; white-space: nowrap; }
.dash-visual td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.share-bar { display: block; height: 4px; margin-top: 4px; background: #e8eef5; border-radius: 2px; overflow: hidden; }
.share-bar b { display: block; height: 100%; background: #118dff; border-radius: 2px; }
.rule-tools { margin-bottom: 8px; }
.rule-list { display: grid; gap: 4px; padding-bottom: 8px; min-height: 40px; }
.rule-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  padding: 8px 8px;
}
.rule-item:hover { background: var(--hover); }
.rule-item.active { background: var(--selected); }
.rule-title { font-weight: 600; overflow-wrap: anywhere; }
.rule-meta { color: var(--text-2); font-size: 12px; font-family: var(--mono); overflow-wrap: anywhere; }
.code-editor { min-height: 220px; font-family: var(--mono); font-size: 12px; line-height: 1.45; }
.mail-block { border-top: 1px solid var(--stroke); padding-top: 12px; }
.mail-block h3 { font-size: 14px; font-weight: 600; margin-bottom: 8px; }

/* Dialogs */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
}
.dialog {
  width: min(440px, 100%);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-dialog);
  padding: 16px 18px 14px;
}
.dialog-sm { width: min(380px, 100%); }
.dialog-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.dialog-head h2 { font-size: 20px; font-weight: 600; }
.dialog-head p { color: var(--text-2); margin-top: 4px; }
.dialog-close { width: 32px; height: 32px; padding: 0; border-color: transparent; }

@media (max-width: 960px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 5;
    border-right: 0;
    border-bottom: 1px solid var(--stroke);
  }
  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .nav-item { width: auto; height: 36px; }
  .sidebar-foot {
    border-top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .user-card { min-width: 0; flex: 1; }
  .page-header { flex-direction: column; align-items: stretch; padding: 16px 16px 4px; }
  .page-header h1 { font-size: 22px; }
  .content { padding: 8px 16px 28px; }
  .split, .field-row, .train-status-hero, .td-form-grid { grid-template-columns: 1fr; display: grid; }
  .train-status-side { text-align: left; }
  .result-row, .kv { grid-template-columns: 1fr; }
  .history-pager { flex-direction: column; align-items: flex-start; }
  .history-pager-controls { flex-wrap: wrap; }
  .actions, .config-actions, .dialog-actions { justify-content: flex-start; }
  .login-panel { padding: 20px 16px; }
  .login-panel h1 { font-size: 22px; }
  .dash-toolbar { flex-direction: column; align-items: stretch; }
  .dash-slicer { justify-content: space-between; }
  .avg-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-matrices { grid-template-columns: 1fr; }
  .matrix-tools, .matrix-pager { flex-direction: column; align-items: stretch; }
  .matrix-pager-controls { flex-wrap: wrap; }
  .dash-visual-wide { grid-column: auto; }

  .history-table, .tokens-table { min-width: 0; }
  .history-table thead, .tokens-table thead { display: none; }
  .history-table tr, .tokens-table tr {
    display: grid;
    gap: 6px;
    padding: 10px 0;
    border-bottom: 1px solid var(--stroke);
  }
  .history-table td, .tokens-table td {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
    border: 0;
    padding: 0;
    text-align: left;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .history-table td[data-label]::before,
  .tokens-table td[data-label]::before {
    content: attr(data-label);
    color: var(--text-2);
    font-size: 12px;
  }
  .dash-visuals { grid-template-columns: 1fr; }
  .os-job-grid, .os-job-map-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .data-table { min-width: 520px; }
  .table-wrap, .chart-block { overflow-x: auto; }
  .ops-board { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .os-job-grid, .os-job-map-grid, .form-cols { grid-template-columns: 1fr; }
  .ops-board { grid-template-columns: 1fr; }
  .ops-metrics { grid-template-columns: 1fr 1fr; }
  .ops-metric-value { font-size: 20px; }
}

#ingest-tabs { margin-bottom: 12px; }
.ingest-panel { min-width: 0; }
.ingest-monitor { margin-top: 4px; }
.ingest-echart { height: 240px; }
.ingest-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
/* Single-row form: field and button share a baseline. Keep help text out of these. */
.inline-form,
.ingest-inline {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin: 8px 0 12px;
}
.inline-form > .field,
.ingest-inline > label { flex: 1 1 220px; min-width: 0; }
.inline-form .btn,
.ingest-inline .btn { height: var(--control-h); }

.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  line-height: 1.35;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-dialog);
  animation: toast-in 160ms ease-out;
}
.toast-ok { background: var(--ok-bg); color: #0b5a0b; border-color: #9fd89f; }
.toast-error { background: var(--bad-bg); color: #6b1210; border-color: #f1bbbc; }
.toast.is-leaving { opacity: 0; transform: translateY(-6px); transition: opacity 160ms ease, transform 160ms ease; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* —— Mobile (≤ 640px) ——
   Touch first: 44px controls, one-column action rows where every button has the
   same width and a single-line label, a compact top bar, and bottom-sheet dialogs. */
@media (max-width: 640px) {
  :root { --field-gap: 14px; --control-h: 44px; }

  /* Shell: brand and actions share the first row, navigation scrolls on the second. */
  .sidebar {
    flex: none;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-auto-rows: max-content;
    align-content: start;
    gap: 8px 12px;
    align-items: center;
    padding: 10px 12px 8px;
  }
  .sidebar-brand { padding: 0; }
  .brand-title { font-size: 18px; }
  .sidebar-nav { grid-column: 1 / -1; grid-row: 2; scroll-snap-type: x proximity; scrollbar-width: none; }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .nav-item { height: 44px; scroll-snap-align: start; }
  .sidebar-foot { display: contents; border-top: 0; margin: 0; padding: 0; }
  .user-card { display: none; }
  .sidebar-actions { grid-column: 2; grid-row: 1; display: flex; gap: 8px; padding: 0; }
  .sidebar-actions .btn { min-width: 112px; }

  .content { padding: 8px 12px 28px; }
  .page-header { padding: 16px 12px 4px; }
  .page-header h1 { font-size: 22px; }
  .page-desc { font-size: 13px; }
  .surface { padding: 4px 12px 14px; }
  .surface-head, .siem-head, .code-head { padding: 12px 0 8px; }
  .overview-hero, .overview-metrics, .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .overview-tile, .kpi { padding: 12px; }
  .overview-value, .kpi-value { font-size: 18px; }

  /* Buttons: one touch size, labels never wrap. */
  .btn, .btn-sm { height: 44px; min-height: 44px; padding: 0 16px; font-size: 15px; white-space: nowrap; }
  .btn-icon { padding: 0 12px; }
  .dialog-close, .copy-btn { height: 44px; }
  .dialog-close { width: 44px; }

  /* Action groups: stacked, full width, equal size. */
  .form-actions, .config-actions, .dialog-actions, .actions,
  .inline-form, .ingest-inline, .package-save,
  .surface-head > .btn, .surface-head > .ingest-toolbar,
  .history-pager-controls, .matrix-pager-controls, .train-loop-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    justify-content: stretch;
    width: 100%;
    padding: 0;
  }
  .form-actions > .btn, .config-actions > .btn, .dialog-actions > .btn, .actions > .btn,
  .inline-form > .btn, .ingest-inline > .btn, .package-save > .btn,
  .surface-head > .btn, .surface-head > .ingest-toolbar > .btn,
  .train-loop-actions > .btn, .matrix-pager-controls > .btn { width: 100%; }
  .ingest-toolbar .badge { justify-self: start; }
  .ingest-toolbar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ingest-toolbar > .badge { grid-column: 1 / -1; }
  .history-pager-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-pager-controls > .history-size { grid-column: 1 / -1; justify-content: space-between; }
  .history-pager-controls > #history-page-label { grid-column: 1 / -1; text-align: center; }
  .history-pager-controls > .history-size select { width: 96px; }
  .history-pager, .ingest-ops-pager { gap: 10px; }

  /* Row actions in card tables: equal-width buttons side by side. */
  .row-actions { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; width: 100%; }
  .row-actions > .btn { width: 100%; }
  .col-actions, .tokens-table td:last-child, .history-table td:last-child { text-align: left; }

  /* Form controls */
  input, textarea, select { font-size: 16px; }
  .field-row, .form-cols, .os-job-grid, .os-job-map-grid, .td-form-grid { grid-template-columns: minmax(0, 1fr); }
  .check-group { gap: 8px 20px; }
  .matrix-tools { display: grid; grid-template-columns: minmax(0, 1fr); }
  .matrix-tools > * { width: 100%; min-width: 0; }
  .config-tabs, .config-tab { height: 44px; }
  .config-grid { gap: 0; }
  .dash-slicer { width: 100%; justify-content: space-between; }
  .dash-slicer select { width: 60%; }

  /* Dialogs become bottom sheets. */
  .dialog-backdrop { place-items: end stretch; padding: 0; }
  .dialog, .dialog-sm { width: 100%; max-width: none; border-radius: var(--radius) var(--radius) 0 0; padding: 16px 16px 20px; }

  /* Login */
  .login-screen { place-items: start center; padding: 16px 12px; }
  .login-panel { margin-top: 24px; }
  .login-panel h1 { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .nav-training-spin { animation: none; }
  input[type="checkbox"]::after { transition: none; }
  .toast { animation: none; }
  .toast.is-leaving { transition: none; }
}

/* Logs */
/* Grid items size to their content by default; let the wide table scroll inside its wrapper instead. */
#panel-logs > .surface { min-width: 0; }
.logs-sub { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.logs-filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px var(--field-gap);
  align-items: end;
  margin: 8px 0 12px;
}
.logs-filters .logs-q { grid-column: span 2; }
.logs-actions { display: flex; gap: 8px; align-items: center; }
.logs-actions .btn { height: var(--control-h); }
.logs-summary { color: var(--text-2); font-size: 12px; min-height: 18px; margin-bottom: 4px; }
.logs-table td { vertical-align: top; }
.logs-row { cursor: pointer; }
.logs-row:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.logs-row.is-open td { background: var(--selected); }
.logs-time { white-space: nowrap; }
.logs-preview {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logs-table .logs-detail td { background: var(--canvas); padding: 12px 16px; text-align: left; }
.logs-detail-inner { position: sticky; left: 16px; }
.logs-detail .kv { margin-bottom: 10px; }
.logs-text {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  max-height: 200px;
  overflow: auto;
  margin: 0 0 10px;
}
.logs-more { display: flex; justify-content: center; padding-top: 10px; }

@media (max-width: 640px) {
  .logs-filters { grid-template-columns: 1fr; }
  .logs-filters .logs-q { grid-column: auto; }
  .logs-preview { max-width: 220px; }
}
