/* ─── Component Library ──────────────────────────────────────────────
   Depends on tokens.css being loaded first.
   Extracted from index.html <style> — all repeating patterns live here.
   ─────────────────────────────────────────────────────────────────── */

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: var(--lh-base);
}
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Accessibility: focus-visible outlines ── */
:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
/* Buttons and nav items use their own rounded shape */
.btn:focus-visible,
.nav-item:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}
/* Improve muted2 contrast to WCAG AA (4.5:1 on --surface) */
.sidebar-section { color: var(--muted); }

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
}

/* ── Sidebar ── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar-logo {
  padding: var(--space-4) var(--space-4) 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.sidebar-logo-icon  { font-size: 22px; }
.sidebar-logo-text  { font-weight: var(--fw-bold); font-size: var(--text-lg); }
.sidebar-logo-ver   { font-size: var(--text-xs); color: var(--muted); margin-top: 1px; }
.sidebar-section {
  padding: var(--space-2) var(--space-2) var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted2);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px var(--space-3);
  border-radius: var(--radius-md);
  margin: 1px var(--space-2);
  cursor: pointer;
  color: var(--muted);
  font-size: var(--text-base);
  transition: background var(--t-fast), color var(--t-fast);
  border: none;
  background: none;
  width: calc(100% - 16px);
  text-align: left;
}
.nav-item:hover  { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface3); color: var(--info); font-weight: var(--fw-semi); }
.nav-icon { width: 16px; text-align: center; flex-shrink: 0; font-size: var(--text-md); }
.nav-badge {
  margin-left: auto;
  background: var(--error);
  color: #fff;
  border-radius: var(--radius-pill);
  padding: 1px var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  min-width: 18px;
  text-align: center;
  animation: pulse 2s infinite;
}
.sidebar-bot-status {
  margin: auto var(--space-3) var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.sbs-label { font-size: var(--text-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 5px; }
.sbs-row   { display: flex; align-items: center; gap: 7px; font-size: var(--text-sm); font-weight: var(--fw-semi); }

/* ── Main ── */
.main { padding: var(--space-5) var(--space-6); overflow-y: auto; }
.page { display: none; }
.page.active { display: block; }
.page-title {
  font-size: var(--text-xl);
  font-weight: var(--fw-bold);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.page-title-sub { font-size: var(--text-sm); color: var(--muted); font-weight: var(--fw-normal); }

/* ── Cards grid ── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px var(--space-4);
}
.card-label {
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--space-2);
}
.card-value { font-size: 26px; font-weight: var(--fw-bold); margin-bottom: 2px; font-variant-numeric: tabular-nums; }
.card-sub   { font-size: var(--text-xs); color: var(--muted); }
.card-ok    { border-color: var(--ok-border); }
.card-warn  { border-color: var(--warn-border); }
.card-error { border-color: var(--error-border); }

/* ── Status dot ── */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-ok    { background: var(--ok);    box-shadow: 0 0 5px var(--ok); }
.dot-warn  { background: var(--warn);  box-shadow: 0 0 5px var(--warn); }
.dot-error { background: var(--error); box-shadow: 0 0 5px var(--error); animation: pulse 2s infinite; }
.dot-info  { background: var(--info); }
.dot-idle  { background: var(--muted2); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  border-radius: var(--radius-2xl);
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--fw-semi);
}
.badge-ok    { background: var(--ok-tint);     color: var(--ok); }
.badge-warn  { background: var(--warn-tint);   color: var(--warn); }
.badge-error { background: var(--error-tint2); color: var(--error); }
.badge-info  { background: var(--info-tint);   color: var(--info); }
.badge-muted { background: var(--surface2);    color: var(--muted); }

/* ── Table ── */
.table-wrap { overflow-x: auto; margin-bottom: var(--space-3); }
table  { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 7px var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid rgba(48,54,61,.5);
  font-size: var(--text-sm);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }
.mono { font-family: var(--mono); font-size: var(--text-xs); }
@media (max-width: 768px) {
  .table-wrap table thead { display: none; }
  .table-wrap table tr { display: block; border-bottom: 1px solid var(--border); padding: var(--space-2) 0; }
  .table-wrap table td { display: block; padding: var(--space-1) var(--space-2); border-bottom: none; }
  .table-wrap table td::before { content: attr(data-label); display: inline-block; font-weight: var(--fw-semi); color: var(--muted); min-width: 120px; font-size: var(--text-xs); }
}

/* ── Section ── */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.section-title   { font-weight: var(--fw-semi); font-size: var(--text-base); display: flex; align-items: center; gap: var(--space-2); }
.section-body    { padding: 14px var(--space-4); }
.section-actions { display: flex; gap: var(--space-2); align-items: center; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 5px var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
}
.btn:hover    { border-color: var(--border2); background: var(--surface3); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary  { background: var(--info); border-color: var(--info); color: #fff; }
.btn-primary:hover { opacity: .85; background: var(--info); }
.btn-danger   { background: var(--error-tint2); border-color: var(--error); color: var(--error); }
.btn-danger:hover  { background: rgba(248,81,73,.25); }
.btn-sm       { padding: 3px 9px; font-size: var(--text-xs); }

/* ── Tag / pill ── */
.tag { display: inline-block; border-radius: var(--radius-sm); padding: 1px 7px; font-size: var(--text-xs); font-weight: var(--fw-semi); white-space: nowrap; }
.tag-mcp      { background: var(--purple-tint); color: var(--purple); }
.tag-rest     { background: var(--info-tint);   color: var(--info); }
.tag-delegate { background: var(--ok-tint);     color: var(--ok); }
.tag-builtin  { background: var(--warn-tint);   color: var(--warn); }

/* ── Logs ── */
.log-toolbar     { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; margin-bottom: var(--space-2); }
.log-filter      { display: flex; gap: var(--space-1); }
.log-filter-btn  { padding: 3px var(--space-2); border-radius: var(--radius-sm); border: 1px solid var(--border); background: none; color: var(--muted); font-size: var(--text-xs); cursor: pointer; }
.log-filter-btn.active { background: var(--surface2); color: var(--text); border-color: var(--border2); }
.log-container   { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-md); max-height: 460px; overflow-y: auto; font-family: var(--mono); font-size: 11.5px; }
.log-line        { display: grid; grid-template-columns: 80px 42px 1fr; gap: var(--space-2); padding: var(--space-1) var(--space-2); border-bottom: 1px solid rgba(48,54,61,.3); align-items: start; }
.log-line:last-child { border-bottom: none; }
.log-line:hover  { background: rgba(255,255,255,.03); }
.log-time        { color: var(--muted2); white-space: nowrap; font-size: 10.5px; padding-top: 1px; }
.log-level       { font-weight: var(--fw-bold); font-size: 10.5px; text-align: center; border-radius: 3px; padding: 1px 3px; }
.ll-info  { color: var(--info); }
.ll-warn  { color: var(--warn); }
.ll-error { color: var(--error); }
.ll-debug { color: var(--muted); }
.ll-fatal { color: var(--error); background: rgba(248,81,73,.2); }
.log-msg       { word-break: break-word; color: var(--text); }
.log-msg-audit { color: var(--purple); }
.log-empty     { padding: var(--space-5); text-align: center; color: var(--muted); }

/* ── Diagnostic ── */
.diag-results { display: flex; flex-direction: column; gap: var(--space-1); }
.diag-item    { display: grid; grid-template-columns: 10px 1fr auto; gap: var(--space-2); padding: 9px var(--space-3); background: var(--surface2); border-radius: 5px; border-left: 3px solid transparent; align-items: start; }
.diag-item.ok    { border-color: var(--ok); }
.diag-item.warn  { border-color: var(--warn); }
.diag-item.error { border-color: var(--error); }
.diag-item.skip  { border-color: var(--muted2); opacity: .7; }
.diag-cat     { font-size: var(--text-xs); font-weight: var(--fw-bold); letter-spacing: .08em; text-transform: uppercase; color: var(--muted2); padding: var(--space-2) 0 var(--space-1); }
.diag-name    { font-weight: var(--fw-semi); font-size: var(--text-sm); margin-bottom: 2px; }
.diag-msg     { font-size: var(--text-xs); color: var(--muted); }
.diag-detail  { font-size: 10.5px; color: var(--muted); font-family: var(--mono); margin-top: 2px; opacity: .7; }
.diag-latency { font-size: 10.5px; color: var(--muted2); white-space: nowrap; padding-top: 2px; }

/* ── Agent cards ── */
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-2); }
.agent-card { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px; }
.agent-card.orchestrator { border-color: var(--purple-border); background: rgba(188,140,255,.04); }
.agent-name      { font-weight: var(--fw-bold); font-size: var(--text-md); margin-bottom: 3px; display: flex; align-items: center; gap: 7px; }
.agent-id        { font-family: var(--mono); font-size: var(--text-xs); color: var(--muted); margin-bottom: var(--space-2); }
.agent-meta      { display: flex; flex-direction: column; gap: 5px; font-size: var(--text-xs); }
.agent-meta-row  { display: flex; justify-content: space-between; align-items: center; color: var(--muted); }
.agent-meta-val  { color: var(--text); font-family: var(--mono); }
.agent-tools       { margin-top: var(--space-2); padding-top: var(--space-2); border-top: 1px solid var(--border); }
.agent-tools-title { font-size: var(--text-xs); color: var(--muted2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .05em; }
.tools-chips { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.tool-chip   { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px 7px; font-size: var(--text-xs); font-family: var(--mono); color: var(--muted); }

/* ── Setup guide ── */
.guide-tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.guide-tab  { background: none; border: none; border-bottom: 2px solid transparent; padding: 7px 14px; cursor: pointer; color: var(--muted); font-size: var(--text-sm); margin-bottom: -1px; transition: color var(--t-fast); }
.guide-tab:hover     { color: var(--text); }
.guide-tab.active    { color: var(--info); border-bottom-color: var(--info); }
.guide-content       { display: none; }
.guide-content.active{ display: block; }
.step      { display: flex; gap: var(--space-3); margin-bottom: var(--space-4); }
.step-num  { background: var(--info); color: #fff; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: var(--text-xs); font-weight: var(--fw-bold); flex-shrink: 0; margin-top: 2px; }
.step-body h4 { font-size: var(--text-sm); font-weight: var(--fw-semi); margin-bottom: var(--space-1); }
.step-body p  { font-size: var(--text-sm); color: var(--muted); margin-bottom: 5px; }
pre.code  { background: var(--surface2); border: 1px solid var(--border); border-radius: 5px; padding: var(--space-2) var(--space-3); font-family: var(--mono); font-size: 11.5px; overflow-x: auto; color: #79c0ff; margin: 5px 0; white-space: pre-wrap; word-break: break-all; }
.cmd-table td:first-child { font-family: var(--mono); color: var(--info); white-space: nowrap; padding-right: var(--space-4); }
.cmd-table td { border-bottom: 1px solid rgba(48,54,61,.4); padding: 6px var(--space-2); font-size: var(--text-sm); }

/* ── Spinner ── */
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--border); border-top-color: var(--info); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Skeleton loader ── */
.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-line { height: 13px; margin-bottom: var(--space-2); }
.skeleton-line.w-75 { width: 75%; }
.skeleton-line.w-50 { width: 50%; }
.skeleton-line.w-33 { width: 33%; }
.skeleton-card { height: 80px; border-radius: var(--radius-lg); }

/* ── Empty state ── */
.empty { color: var(--muted); font-size: var(--text-sm); padding: 14px 0; text-align: center; }
.empty-state {
  text-align: center;
  padding: var(--space-10) var(--space-5);
  color: var(--muted);
}
.empty-state-icon  { font-size: 36px; margin-bottom: var(--space-3); }
.empty-state-title { font-size: var(--text-md); font-weight: var(--fw-semi); color: var(--text); margin-bottom: var(--space-1); }
.empty-state-desc  { font-size: var(--text-sm); max-width: 320px; margin: 0 auto; }

/* ── Settings forms ── */
.settings-row {
  display: grid;
  grid-template-columns: 200px 1fr 130px auto;
  gap: var(--space-2);
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }
.settings-label  { font-size: var(--text-sm); color: var(--muted); font-weight: var(--fw-medium); }
.settings-input  {
  padding: 6px var(--space-2);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: var(--text-sm);
  font-family: var(--mono);
  outline: none;
  width: 100%;
  transition: border-color var(--t-fast);
}
.settings-input:focus  { border-color: var(--info); }
.settings-status { font-size: var(--text-xs); text-align: right; }
@media (max-width: 700px) {
  .settings-row { grid-template-columns: 1fr 1fr; }
  .settings-label { grid-column: 1 / -1; }
}

/* ── SOC Platform ── */
.int-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--space-2); }
.int-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) 14px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transition: border-color var(--t-base), opacity var(--t-base);
}
.int-card.active   { border-color: var(--ok-border); }
.int-card.inactive { opacity: .5; }
.int-icon   { font-size: 20px; flex-shrink: 0; }
.int-body   { flex: 1; min-width: 0; }
.int-name   { font-weight: var(--fw-semi); font-size: var(--text-sm); margin-bottom: 2px; }
.int-status { font-size: 10.5px; color: var(--muted); }
.int-url    { font-size: var(--text-xs); color: var(--muted2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; margin-top: 2px; }

.flag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--space-2); margin-bottom: var(--space-4); }
.flag-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: var(--space-2) 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: border-color var(--t-base);
}
.flag-card.card-ok { border-color: var(--ok-border); }
.flag-name { font-size: var(--text-sm); font-weight: var(--fw-semi); }
.flag-desc { font-size: var(--text-xs); color: var(--muted); margin-top: 2px; }

.approval-card {
  background: var(--surface);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-lg);
  padding: 14px var(--space-4);
  margin-bottom: var(--space-2);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-3);
  align-items: start;
  transition: border-color var(--t-base);
}
.approval-card:hover { border-color: var(--error-border-h); }
.approval-id     { font-family: var(--mono); font-size: var(--text-base); font-weight: var(--fw-bold); color: var(--error); }
.approval-action { font-size: var(--text-sm); margin-top: var(--space-2); padding: var(--space-2) var(--space-2); background: var(--surface2); border-radius: 5px; border-left: 3px solid var(--soc); line-height: var(--lh-base); }
.approval-btns   { display: flex; flex-direction: column; gap: var(--space-1); flex-shrink: 0; }

.soc-alert-banner {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 14px;
  background: var(--error-tint);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
  cursor: pointer;
}
.soc-alert-banner:hover { background: var(--error-tint2); }

/* ── Utility classes ── */
.flex        { display: flex; }
.items-center{ align-items: center; }
.gap-8       { gap: var(--space-2); }
.flex-1      { flex: 1; }
.text-muted  { color: var(--muted); }
.text-ok     { color: var(--ok); }
.text-error  { color: var(--error); }
.text-warn   { color: var(--warn); }
.mb-8        { margin-bottom: var(--space-2); }
.mb-12       { margin-bottom: var(--space-3); }
code { font-family: var(--mono); font-size: var(--text-xs); background: var(--surface2); padding: 1px 5px; border-radius: 3px; }
