:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #16191f;
  --muted: #6b7280;
  --accent: #3b5bdb;
  --accent-ink: #ffffff;
  --accent-soft: #e8edff;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --warn-bg: #fff4e6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);

  --sev-low: #5c7cfa;      --sev-low-bg: #edf2ff;
  --sev-medium: #e67700;   --sev-medium-bg: #fff4e6;
  --sev-high: #d9480f;     --sev-high-bg: #fff0e6;
  --sev-critical: #c92a2a; --sev-critical-bg: #fff0f0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e6e8ec;
    --muted: #8b93a1;
    --accent: #748ffc;
    --accent-ink: #0f1115;
    --accent-soft: #1f2640;
    --danger: #ff6b6b;
    --ok: #51cf66;
    --warn-bg: #2b2111;
    --shadow: none;
    --sev-low-bg: #1d2440; --sev-medium-bg: #2e2412; --sev-high-bg: #2f1d12; --sev-critical-bg: #321618;
    --sev-low: #91a7ff; --sev-medium: #ffa94d; --sev-high: #ff8c42; --sev-critical: #ff6b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0; }
h3.label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.mono { word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 48px); box-sizing: content-box; }
main.wrap { padding-top: 24px; padding-bottom: 48px; }
main.center { min-height: 100vh; display: grid; place-items: center; padding-top: 0; }

/* ---------- top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo-pic { display: inline-flex; flex: none; }
.logo-pic img { display: block; width: 28px; height: 28px; }
.logo-pic.lg { justify-content: center; }
.logo-pic.lg img { width: 72px; height: 72px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 7px; font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { color: var(--text); background: var(--surface-2); }
.who { display: flex; align-items: center; gap: 10px; }
.who-name { color: var(--text); font-weight: 500; }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card.pad, .pad { padding: 20px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; padding: 16px 20px 12px; }
.narrow { max-width: 460px; }
.narrow h2 { margin-bottom: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; }

input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 36px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--accent); }
label { display: grid; gap: 6px; font-weight: 550; font-size: 13px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 450; }
.stack { display: grid; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; align-items: end; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; padding: 3px; margin: 0; gap: 2px; background: var(--surface-2); width: fit-content; }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 5px 16px; border-radius: 7px; cursor: pointer; font-weight: 550; color: var(--muted); }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--accent-soft); border: 1px solid transparent; }
.flash.error { background: var(--sev-critical-bg); color: var(--danger); }

/* ---------- tags ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.sev-low { color: var(--sev-low); background: var(--sev-low-bg); }
.sev-medium { color: var(--sev-medium); background: var(--sev-medium-bg); }
.sev-high { color: var(--sev-high); background: var(--sev-high-bg); }
.sev-critical { color: var(--sev-critical); background: var(--sev-critical-bg); }

.tlp { display: inline-block; background: #000; padding: 1px 7px; border-radius: 4px; font: 600 11px/1.6 ui-monospace, Menlo, monospace; white-space: nowrap; }
.tlp-clear { color: #fff; } .tlp-green { color: #33ff00; } .tlp-amber { color: #ffc000; } .tlp-red { color: #ff2b2b; }

.kind { font-size: 12.5px; font-weight: 550; }
.kind-alerta { color: var(--text); }
.kind-evento { color: var(--muted); }
.tag { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 5px; background: var(--surface-2); color: var(--muted); font-size: 11.5px; font-weight: 550; }
.node-tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font: 600 12px/1.4 ui-monospace, Menlo, monospace; }
.node-tag.hub { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.node-tag.sm { font-size: 11px; padding: 1px 6px; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.dot.ok { background: var(--ok); }

/* ---------- list ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pills { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; padding: 14px 16px; border-radius: var(--radius); border: 1px solid transparent; }
.stat:hover { text-decoration: none; filter: brightness(.98); }
.stat.on { border-color: currentColor; }
.stat-n { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 12.5px; font-weight: 600; opacity: .85; }

.filters { display: flex; gap: 8px; padding: 12px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1 1 260px; width: auto; }
.filters select { width: auto; flex: 0 0 auto; }

.table-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .c-check { width: 36px; padding-right: 0; }
.table .c-name { width: 100%; min-width: 240px; }
.table .c-name a { color: var(--text); font-weight: 550; }
.table.compact td { padding: 6px 14px; font-size: 13px; }
.table tr.dim td { opacity: .55; }
.table tr.warn td { background: var(--warn-bg); }
.log { max-height: 420px; overflow-y: auto; }

.bulkbar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--accent-soft); font-weight: 550; }
.bulkbar[hidden] { display: none; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 12px; border-top: 1px solid var(--border); }
.empty { text-align: center; padding: 56px 20px; }
.empty p { margin: 4px 0; }

/* ---------- detail ---------- */
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.side .card { margin-bottom: 12px; }
.prose { white-space: pre-wrap; line-height: 1.6; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.checklist { display: grid; gap: 8px; }

/* ---------- admin ---------- */
.admin-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.admin-grid .card { margin-bottom: 0; }
.admin-grid + .card { margin-top: 16px; }
.inline-form { display: flex; gap: 8px; padding: 14px 20px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.inline-form input { flex: 1 1 140px; width: auto; }
.mini-form { display: flex; gap: 6px; }
.mini-form input { width: 150px; min-height: 30px; padding: 4px 8px; }
.mini-form select { width: auto; min-height: 30px; padding: 3px 8px; font: 600 12px/1.4 ui-monospace, Menlo, monospace; }

/* ---------- dialog / login ---------- */
.dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(15, 17, 21, .45); }
.dialog form { padding: 20px 22px; }
.dialog-head, .dialog-foot { display: flex; align-items: center; justify-content: space-between; }
.dialog-foot { justify-content: flex-end; gap: 8px; padding-top: 4px; }

.login-card { width: min(380px, calc(100vw - 32px)); padding: 28px; }
.login-head { text-align: center; margin-bottom: 20px; }
.login-head h1 { margin-top: 12px; font-size: 20px; }
.login-head p { margin: 4px 0 0; }

@media (max-width: 860px) {
  .detail, .admin-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid3 { grid-template-columns: 1fr; }
  .nav { display: none; }
  .who-name { display: none; }
  .topbar-inner { justify-content: space-between; }
  .page-head { align-items: stretch; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .filters > * { flex: 1 1 100%; width: 100%; }
  .filters select { width: 100%; }
  .table .c-name { min-width: 200px; }
}
body { overflow-x: hidden; }

/* ---------- visibility ---------- */
[hidden] { display: none !important; }
.tag.aud-global { background: var(--accent-soft); color: var(--accent); }
.tag.aud-to { max-width: 220px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; white-space: nowrap; }

.new-user { display: grid; grid-template-columns: 1fr 1fr 1.2fr auto; gap: 12px; align-items: end; padding-top: 4px; }
.hint { padding: 0 20px 16px; margin: 0; }
@media (max-width: 860px) {
  .new-user { grid-template-columns: 1fr; }
}

/* ---------- status / type ---------- */
.seg-row { display: flex; gap: 10px; flex-wrap: wrap; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; }
.status-ongoing { color: var(--sev-medium); }
.status-ongoing::before { background: var(--sev-medium); box-shadow: 0 0 0 3px var(--sev-medium-bg); animation: pulse 1.8s ease-in-out infinite; }
.status-occurred { color: var(--muted); }
.status-occurred::before { background: var(--ok); }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .status-ongoing::before { animation: none; } }
.otype { display: inline-block; padding: 1px 7px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border); font: 500 11.5px/1.6 ui-monospace, Menlo, monospace; white-space: nowrap; }
.kind-mini { display: block; font-size: 10.5px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); line-height: 1.3; }

/* ---------- attachments ---------- */
.files { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 2px; }
.files li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; margin: 0 -8px; border-radius: 7px; }
.files li:hover { background: var(--surface-2); }
.file-main { display: grid; min-width: 0; flex: 1; }
.file-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-name::before { content: "📄 "; }
.upload { gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.upload p { margin: 0; }
input[type=file] { padding: 6px; font-size: 13px; }
input[type=file]::file-selector-button { font: inherit; font-weight: 550; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 6px; padding: 4px 10px; margin-right: 10px; cursor: pointer; }

/* ---------- chat ---------- */
.main-col { display: grid; gap: 16px; min-width: 0; }
.main-col > .card { margin-bottom: 0; }
.chat .card-head { border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.closed { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .05em; }
.chat-log { display: flex; flex-direction: column; gap: 10px; padding: 16px 20px; max-height: 420px; overflow-y: auto; }
.chat-empty { margin: 8px 0; text-align: center; }
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 78%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 8px 12px; border-radius: 12px 12px 12px 4px; background: var(--surface-2); border: 1px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.msg.hub .bubble { background: var(--accent-soft); border-color: transparent; }
.msg.mine .bubble { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); border-radius: 12px 12px 4px 12px; }
.msg-meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; padding: 0 4px; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; padding: 12px 20px 16px; border-top: 1px solid var(--border); }
.chat-form textarea { resize: none; min-height: 40px; max-height: 160px; }
.chat-closed { padding: 12px 20px 16px; margin: 0; border-top: 1px solid var(--border); }
.tag.unread { background: var(--accent); color: var(--accent-ink); }

/* ---------- read-only record ---------- */
.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 20px; margin: 0 0 20px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.fields dt { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.fields dd { margin: 0; font-weight: 550; }
@media (max-width: 860px) { .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- IoCs, references, correlations ---------- */
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; align-items: end; }
.grid3 .span2 { grid-column: span 2; }
.mono-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
details.more { border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; }
details.more summary { cursor: pointer; font-weight: 550; font-size: 13px; color: var(--muted); }
details.more[open] summary { margin-bottom: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-top: 20px; }
.section-head .label { margin: 0; }
.section-gap { margin-top: 20px !important; }
.table.iocs { margin-top: 8px; border: 1px solid var(--border); border-radius: 8px; }
.table.iocs td.mono { word-break: break-all; }
.refs { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.refs a { word-break: break-all; }
.corr { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.corr li { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.corr .mono { word-break: break-all; }
.corr-link { display: inline-flex; gap: 4px; align-items: center; font-weight: 600; }
.tag.corr-count { background: var(--sev-medium-bg); color: var(--sev-medium); }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } .grid3 .span2 { grid-column: auto; } }

/* ---------- drafts ---------- */
.tag.draft { background: var(--sev-critical-bg); color: var(--sev-critical); text-transform: uppercase; letter-spacing: .04em; font-size: 10.5px; margin-left: 0; }
.draft-mini { color: var(--sev-critical); }
.draft-banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 16px; border-radius: var(--radius); border: 1px dashed var(--sev-critical); background: var(--sev-critical-bg); color: var(--text); }
.draft-banner:hover { text-decoration: none; filter: brightness(1.05); }
.draft-notice { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; margin-bottom: 16px; border-radius: var(--radius); border: 1px dashed var(--sev-critical); background: var(--sev-critical-bg); flex-wrap: wrap; }
.draft-notice .tag { margin-right: 6px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn.disabled, .btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
