:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-muted: #f7f9fc;
  --border: #dde4ee;
  --text: #1b2433;
  --text-muted: #667289;
  --navy: #101a2b;
  --navy-soft: #1b2942;
  --accent: #2c6ef2;
  --accent-dark: #1d54c4;
  --ok: #13795b;
  --ok-bg: #e4f6ef;
  --warn: #9a6200;
  --warn-bg: #fff3d6;
  --danger: #b42318;
  --danger-bg: #fde8e7;
  --info: #1f5fbf;
  --info-bg: #e6efff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 26, 43, 0.04), 0 8px 24px rgba(16, 26, 43, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: 24px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
ul, ol { margin: 0 0 10px; padding-left: 20px; }
li { margin-bottom: 4px; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--surface-muted); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }
pre code { border: 0; padding: 0; background: none; }
img { max-width: 100%; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Application shell ------------------------------------------------------ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 248px;
  display: flex; flex-direction: column; gap: 18px;
  padding: 20px 14px;
  background: linear-gradient(180deg, var(--navy) 0%, #0b1422 100%);
  color: #d7e0ef;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 10px; color: #fff; padding: 4px 8px; }
.brand:hover { text-decoration: none; }
.brand strong { display: block; font-size: 16px; letter-spacing: 0.2px; }
.brand small { display: block; color: #8ea1bd; font-size: 11px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 10px; background: linear-gradient(135deg, #3d82ff, #1a4cb8);
  color: #fff; font-weight: 700; font-size: 14px; letter-spacing: 0.5px;
  box-shadow: 0 6px 14px rgba(44, 110, 242, 0.35);
}

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: #b9c6da; font-weight: 500;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; text-decoration: none; }
.nav-item.is-active { background: rgba(61, 130, 255, 0.18); color: #fff; box-shadow: inset 2px 0 0 #4d8cff; }
.nav-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: #d9534f; color: #fff; font-size: 11px; font-weight: 700;
}

.sidebar-footer { margin-top: auto; padding: 10px 11px; border-top: 1px solid rgba(255, 255, 255, 0.1); }
.env-pill {
  display: inline-block; padding: 2px 8px; margin-bottom: 4px;
  border-radius: 999px; background: rgba(255, 255, 255, 0.12);
  color: #dce6f5; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
}
.sidebar-footer .muted { color: #7f91ac; }

.main-wrap { flex: 1; min-width: 0; margin-left: 248px; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.company-block { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.company-block strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.user-block { display: flex; flex-direction: column; line-height: 1.2; text-align: right; }
.user-name { font-weight: 600; }
.notification-link { position: relative; color: var(--text-muted); font-weight: 500; white-space: nowrap; }
.notification-link:hover { color: var(--accent); }
.notification-link .nav-count { position: absolute; top: -8px; right: -16px; }

.icon-button { display: none; }

.content { flex: 1; width: 100%; max-width: 1440px; margin: 0 auto; padding: 24px; }
.footer {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 14px 24px; border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 12px;
}

/* Buttons and forms ------------------------------------------------------ */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 7px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.button:hover { background: var(--surface-muted); text-decoration: none; }
.button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid rgba(44, 110, 242, 0.45); outline-offset: 1px;
}
.button-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.button-ghost { background: var(--surface); }
.button-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button-danger:hover { background: #921d13; border-color: #921d13; }
.button-small { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.button-wide { width: 100%; }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.inline-form { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.inline-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
label > span { color: var(--text-muted); }
input[type="text"], input[type="password"], input[type="search"], input[type="number"],
input[type="email"], input[type="file"], select, textarea {
  width: 100%; min-height: 36px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 80px; resize: vertical; }
input[readonly] { background: var(--surface-muted); }
.inline-label { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.inline-label select { width: auto; }

/* Alerts and badges ------------------------------------------------------ */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); color: var(--ok); border-color: #b9e6d7; }
.alert-warning { background: var(--warn-bg); color: var(--warn); border-color: #f2dca8; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: #f3c2bd; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: #c4d9fa; }
.alert p:last-child { margin-bottom: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-muted); color: var(--text-muted);
  border: 1px solid var(--border); font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: #b9e6d7; }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: #f2dca8; }
.badge-danger { background: var(--danger-bg); color: var(--danger); border-color: #f3c2bd; }
.badge-info { background: var(--info-bg); color: var(--info); border-color: #c4d9fa; }
.badge-neutral { background: #eef1f6; color: #4a576b; }

.tone-ok { color: var(--ok); }
.tone-warn { color: var(--warn); }
.tone-danger { color: var(--danger); }
.tone-info { color: var(--info); }

/* Page structure --------------------------------------------------------- */
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.page-heading h1 { margin-bottom: 2px; }
.page-subtitle { color: var(--text-muted); margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { min-width: 0; }
.text-link { font-weight: 600; font-size: 13px; }

.two-column { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.two-column > .card { margin-bottom: 0; }
.two-column-wide { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.two-column + .card, .two-column + .two-column, .detail-grid + .card { margin-top: 20px; }

.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.detail-grid > .card { margin-bottom: 20px; }

/* Stats ----------------------------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-grid.compact { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
}
.stat-label { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.2; margin-top: 4px; }
.stat-value-small { font-size: 15px; font-weight: 600; }
.stat-hint { color: var(--text-muted); font-size: 11.5px; margin-top: 2px; }

.check-strip { display: flex; gap: 10px; flex-wrap: wrap; }
.check-pill {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 100px; padding: 10px; border-radius: var(--radius-sm);
  background: var(--surface-muted); border: 1px solid var(--border);
}
.check-pill strong { font-size: 20px; }
.check-pill span { font-size: 11.5px; color: var(--text-muted); }

.status-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.status-cell {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

/* Tables ---------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
thead th {
  text-align: left; padding: 9px 11px; background: var(--surface-muted);
  border-bottom: 1px solid var(--border); color: var(--text-muted);
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap;
}
tbody td { padding: 9px 11px; border-bottom: 1px solid #edf1f7; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcff; }
tr.subrow td { background: var(--surface-muted); }
tr.subrow:hover { background: var(--surface-muted); }

.pagination { display: flex; align-items: center; gap: 12px; justify-content: flex-end; margin-top: 12px; }

.item-list { list-style: none; padding: 0; margin: 0; }
.item-list li {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid #edf1f7;
}
.item-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.item-main { min-width: 0; }

.empty-state {
  padding: 28px 16px; text-align: center;
  color: var(--text-muted); background: var(--surface-muted);
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
}

/* Filters --------------------------------------------------------------- */
.filter-card { padding: 14px 16px; }
.filters { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.filters label { min-width: 180px; flex: 1 1 180px; }
.filter-actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* Definition lists, code, prose ---------------------------------------- */
.definition-list { display: grid; grid-template-columns: minmax(120px, 0.4fr) minmax(0, 1fr); gap: 8px 16px; margin: 0; }
.definition-list dt { color: var(--text-muted); font-weight: 600; font-size: 12.5px; }
.definition-list dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.code-block {
  margin: 0 0 10px; padding: 12px; overflow-x: auto;
  background: #0f1726; color: #d6e2f3; border-radius: var(--radius-sm);
  border: 1px solid #1e2b41; white-space: pre-wrap; overflow-wrap: anywhere;
}
.code-small { font-size: 11.5px; padding: 9px; }
.prose { color: var(--text); }
.prose code { white-space: nowrap; }
.details { margin-top: 6px; }
.details summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 12.5px; }
.details[open] summary { margin-bottom: 8px; }

/* Timeline -------------------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; display: flex; gap: 12px; padding: 0 0 16px 0; }
.timeline li::before {
  content: ""; position: absolute; left: 5px; top: 14px; bottom: 0; width: 1px; background: var(--border);
}
.timeline li:last-child::before { display: none; }
.timeline-marker { width: 11px; height: 11px; margin-top: 4px; border-radius: 50%; background: var(--text-muted); flex: 0 0 11px; }
.timeline-marker.tone-ok { background: var(--ok); }
.timeline-marker.tone-warn { background: #d9a300; }
.timeline-marker.tone-danger { background: var(--danger); }
.timeline-marker.tone-info { background: var(--info); }
.timeline-body { min-width: 0; flex: 1; }
.timeline-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* Progress and bars ----------------------------------------------------- */
progress { width: 100%; height: 8px; border: 0; border-radius: 999px; overflow: hidden; background: #e9eef6; }
progress::-webkit-progress-bar { background: #e9eef6; }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }
.bar-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.bar-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 3px; }

/* Diagnostics, agents --------------------------------------------------- */
.diagnostic-list { display: flex; flex-direction: column; gap: 14px; }
.diagnostic { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; background: var(--surface-muted); }
.diagnostic-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 10px 0; }
.diagnostic-grid h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); margin-bottom: 4px; }
.diagnostic-grid ul { padding-left: 18px; margin: 0; }
.recommendation { padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.agent-answer { margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; background: var(--surface-muted); }
.answer-text { white-space: pre-wrap; font-size: 13.5px; overflow-wrap: anywhere; }
.agent-catalog { display: flex; flex-direction: column; gap: 10px; }
.catalog-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; background: var(--surface-muted); }
.catalog-item h3 { margin-bottom: 4px; }
.catalog-item p { color: var(--text-muted); font-size: 12.5px; margin-bottom: 6px; }
.chip-row { display: flex; gap: 5px; flex-wrap: wrap; }
.chip { display: inline-block; padding: 2px 7px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); font-size: 11px; }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-muted); }
.history-item summary { cursor: pointer; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.history-item .answer-text { margin-top: 10px; }

.scenario-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }

/* Secrets and notifications -------------------------------------------- */
.secret-alert { display: flex; flex-direction: column; gap: 10px; }
.secret-row { display: flex; gap: 8px; align-items: center; }
.secret-row input { font-family: var(--mono); }
.reject-form input[type="text"] { width: 130px; min-height: 30px; padding: 4px 8px; font-size: 12.5px; }
.notification-list { list-style: none; margin: 0; padding: 0; }
.notification-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid #edf1f7; }
.notification-item:last-child { border-bottom: 0; }
.notification-main { min-width: 0; }
.notification-main p { margin: 4px 0 6px; color: var(--text-muted); }

/* Login and error ------------------------------------------------------- */
.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 28px; background:
    radial-gradient(900px 500px at 12% 15%, rgba(44, 110, 242, 0.18), transparent 60%),
    radial-gradient(700px 500px at 88% 85%, rgba(19, 121, 91, 0.12), transparent 60%),
    #eef2f9;
}
.login-layout {
  width: 100%; max-width: 1040px;
  display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: 0 24px 70px rgba(16, 26, 43, 0.14); overflow: hidden;
}
.login-intro { padding: 42px; background: linear-gradient(160deg, var(--navy) 0%, #16233a 100%); color: #e6edf8; }
.brand-large { padding: 0; margin-bottom: 28px; }
.brand-large .brand-mark { width: 46px; height: 46px; flex-basis: 46px; font-size: 16px; }
.brand-large strong { font-size: 20px; }
.login-intro h1 { font-size: 27px; margin-bottom: 14px; color: #fff; }
.login-lead { color: #b7c6dc; font-size: 14.5px; }
.feature-list { list-style: none; padding: 0; margin: 24px 0 0; display: flex; flex-direction: column; gap: 10px; }
.feature-list li { position: relative; padding-left: 26px; color: #cfdaea; }
.feature-list li::before {
  content: "✓"; position: absolute; left: 0; top: 0; color: #6ea2ff; font-weight: 700;
}
.login-card { padding: 42px; display: flex; flex-direction: column; justify-content: center; }
.login-card h2 { font-size: 22px; margin-bottom: 18px; }
.login-note { margin-top: 18px; padding: 12px; border-radius: var(--radius-sm); background: var(--info-bg); color: var(--info); border: 1px solid #c4d9fa; font-size: 12.5px; }
.login-note p { margin: 4px 0 0; }
.login-card .muted { margin-top: 14px; }

.error-card {
  max-width: 560px; padding: 36px; text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow);
}
.error-card .brand { justify-content: center; color: var(--text); margin-bottom: 18px; }
.error-card .brand small { color: var(--text-muted); }
.error-code { font-size: 52px; font-weight: 800; color: var(--accent); line-height: 1; }
.error-card h1 { margin: 10px 0; }
.error-card .button-row { justify-content: center; margin-top: 18px; }

/* Responsive ------------------------------------------------------------ */
@media (max-width: 1100px) {
  .two-column, .two-column-wide, .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .two-column > .card { margin-bottom: 0; }
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; width: 260px; }
  .sidebar.is-open { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(9, 16, 28, 0.45); }
  .main-wrap { margin-left: 0; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .icon-button {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 34px; padding: 5px 10px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface); font: inherit; font-weight: 600; cursor: pointer;
  }
  .topbar-actions { margin-left: 0; width: 100%; justify-content: flex-start; gap: 10px; }
  .user-block { text-align: left; }
  .content { padding: 16px; }
  .footer { flex-direction: column; gap: 4px; padding: 12px 16px; }
  .login-layout { grid-template-columns: 1fr; }
  .login-intro { display: none; }
  .login-card, .login-intro { padding: 28px; }
  .page-heading { flex-direction: column; }
  .form-row { grid-template-columns: 1fr; }
  .diagnostic-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters label { flex-basis: 100%; }
  .secret-row { flex-direction: column; align-items: stretch; }
  .notification-item { flex-direction: column; }
}

@media print {
  .sidebar, .topbar, .footer, .button, .inline-form, .details { display: none !important; }
  .main-wrap { margin-left: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
