/* FINN Agent Control — Instrument design system
   Blued-charcoal ground, monospace telemetry, functional signal colour.
   No web fonts: strict CSP (style-src 'self'). System stacks only. */

:root {
  --bg: #0d1621;
  --panel: #132030;
  --panel-2: #16273a;
  --raise: #1a2b3d;
  --line: #233648;
  --hair: #1b2c3c;

  --ink: #d9e4ef;
  --muted: #7f97ab;
  --muted-2: #5f7688;

  --green: #41c08a;
  --amber: #e2ab4c;
  --red: #e86663;
  --cyan: #54bad6;

  --green-soft: #12281f;
  --amber-soft: #2b2213;
  --red-soft: #2c1918;
  --cyan-soft: #10242c;

  --shadow: 0 1px 0 rgba(255, 255, 255, .02), 0 14px 34px rgba(0, 0, 0, .38);

  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Code", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;

  color-scheme: dark;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

.eyebrow {
  margin: 0 0 7px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-2);
  flex: 0 0 auto;
}
.status-dot.good { background: var(--green); }
.status-dot.danger { background: var(--red); }
.status-dot.unknown { background: var(--amber); }
.status-dot.neutral { background: var(--cyan); }

/* ---------- Shell ---------- */

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: #0f2732;
  border: 1px solid #1d4657;
  color: var(--cyan);
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: .02em;
}

.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 244px;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  background: linear-gradient(180deg, #101d2b, #0b141f);
  border-right: 1px solid var(--line);
  color: var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 6px 26px;
  color: var(--ink);
  text-decoration: none;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; letter-spacing: -.01em; }
.brand small {
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .2em;
  color: var(--muted-2);
}

.sidebar nav { display: flex; flex-direction: column; gap: 3px; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 7px;
  border: 1px solid transparent;
  color: var(--muted);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 500;
}
.sidebar nav a span {
  width: 18px;
  text-align: center;
  font-size: 14px;
  color: var(--muted-2);
}
.sidebar nav a:hover { color: var(--ink); }
.sidebar nav a.active {
  background: #14202e;
  border-color: #1f3547;
  color: var(--ink);
  box-shadow: inset 2px 0 0 var(--cyan);
}
.sidebar nav a.active span { color: var(--cyan); }
.sidebar nav a.disabled { cursor: not-allowed; opacity: .4; }
.sidebar nav em {
  margin-left: auto;
  padding: 2px 6px;
  border-radius: 9px;
  background: var(--panel-2);
  font-family: var(--mono);
  font-size: 9px;
  font-style: normal;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar-boundary {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: auto;
  padding: 14px 10px 4px;
  border-top: 1px solid var(--hair);
}
.sidebar-boundary strong, .sidebar-boundary small { display: block; }
.sidebar-boundary strong { font-size: 11px; }
.sidebar-boundary small { margin-top: 4px; color: var(--muted-2); font-size: 10px; }

.main {
  grid-column: 2;
  padding: 26px 34px 24px;
  min-width: 0;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--hair);
}
.topbar h1 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -.03em; }
.top-actions { display: flex; align-items: center; gap: 18px; }
.refresh { font-family: var(--mono); font-size: 11px; color: var(--muted-2); }
.profile { display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; }
.profile > span {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #0f2732;
  border: 1px solid #1d4657;
  color: var(--cyan);
  font-family: var(--mono);
  font-weight: 700;
}
.profile strong, .profile small { display: block; }
.profile strong { font-size: 12px; }
.profile small { font-size: 10px; color: var(--muted-2); text-transform: capitalize; }
.text-button {
  padding: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Global status banner ---------- */

.global-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--muted-2);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.global-banner p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; }
.status-title { display: flex; gap: 10px; align-items: center; }
.status-title strong { font-family: var(--mono); font-size: 20px; letter-spacing: .05em; }

.pulse {
  position: relative;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--muted-2);
  flex: 0 0 auto;
}
.pulse::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: inherit;
  opacity: .28;
  animation: pulse-ring 2.6s ease-in-out infinite;
}
@keyframes pulse-ring {
  0%, 100% { transform: scale(1); opacity: .28; }
  50% { transform: scale(1.6); opacity: 0; }
}

.status-degraded { border-left-color: var(--amber); }
.status-degraded .pulse { background: var(--amber); }
.status-unknown { border-left-color: var(--amber); }
.status-unknown .pulse { background: var(--amber); }
.status-killed { border-left-color: var(--red); }
.status-killed .pulse { background: var(--red); }
.status-observe_only { border-left-color: var(--green); }
.status-observe_only .pulse { background: var(--green); }
.status-live { border-left-color: var(--green); }
.status-live .pulse { background: var(--green); }

.banner-facts { display: flex; gap: 24px; }
.banner-facts span {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.banner-facts strong { font-size: 12.5px; color: var(--ink); letter-spacing: .02em; }

/* ---------- Issue center ---------- */

.issue-strip {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  border-radius: 9px;
  background: var(--panel);
}
.issue-strip > div { display: flex; gap: 12px; }
.issue-strip h2, .issue-strip p { margin: 0; }
.issue-strip h2 { font-size: 12.5px; }
.issue-strip p { margin-top: 3px; color: var(--muted); font-size: 11.5px; }
.issue-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 6px;
  background: var(--red-soft);
  border: 1px solid var(--red);
  color: var(--red);
  font-family: var(--mono);
  font-weight: 700;
}
.issue-strip details { max-width: 55%; font-size: 11px; color: var(--cyan); }
.issue-strip summary { cursor: pointer; font-weight: 700; font-family: var(--mono); letter-spacing: .04em; }
.issue-strip ul {
  position: absolute;
  right: 34px;
  z-index: 2;
  width: min(560px, 70vw);
  margin-top: 10px;
  padding: 14px 18px;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  box-shadow: var(--shadow);
  color: var(--ink);
}
.issue-strip li { margin: 8px 0; padding-left: 11px; border-left: 2px solid var(--muted-2); }
.issue-strip li.level-fail { border-left-color: var(--red); }
.issue-strip li.level-warn { border-left-color: var(--amber); }

/* ---------- Metric readouts ---------- */

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--line);
}
.metric-card {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 120px;
  padding: 15px 16px 13px;
  background: var(--panel);
}
.metric-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--muted);
}
.metric-card > strong { font-family: var(--mono); font-size: 19px; font-weight: 600; letter-spacing: 0; }
.metric-card > small { color: var(--muted-2); font-size: 10.5px; }
.metric-card.level-danger > strong { color: var(--red); }

.signal { display: flex; gap: 2px; margin-top: auto; }
.signal b { width: 5px; height: 11px; background: #22374a; display: block; }
.metric-card.level-good .signal b { background: var(--green); }
.metric-card.level-neutral .signal b:nth-child(-n+3) { background: var(--cyan); }
.metric-card.level-unknown .signal b:nth-child(-n+2) { background: var(--amber); }
.metric-card.level-danger .signal b:nth-child(1) { background: var(--red); }

/* ---------- Panels ---------- */

.panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--hair);
}
.panel-header h2 { margin: 0; font-size: 15px; letter-spacing: -.01em; }
.panel-header .eyebrow { margin-bottom: 4px; }

.button {
  display: inline-block;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { border-color: var(--cyan); }
.button:disabled { cursor: not-allowed; opacity: .5; }
.button-primary { border-color: #1d4657; background: #0f2b37; color: var(--cyan); }

.empty-state {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px 20px;
  background: repeating-linear-gradient(-45deg, var(--panel), var(--panel) 10px, #142234 10px, #142234 20px);
}
.empty-symbol {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 22px;
}
.empty-state h3, .empty-state p { margin: 0; }
.empty-state h3 { font-size: 13.5px; }
.empty-state p { max-width: 730px; margin-top: 5px; color: var(--muted); font-size: 11.5px; line-height: 1.5; }
.empty-state .badge { margin-left: auto; }

.badge {
  display: inline-block;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .08em;
}

.two-column {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 14px;
}
.wide { grid-column: 1 / -1; }

.quality-grid { display: grid; grid-template-columns: 1fr 1fr; }
.quality-grid > div {
  padding: 16px 18px;
  border-right: 1px solid var(--hair);
  border-bottom: 1px solid var(--hair);
}
.quality-grid > div:nth-child(even) { border-right: 0; }
.quality-grid > div:nth-last-child(-n+2) { border-bottom: 0; }
.quality-grid span, .quality-grid strong, .quality-grid small { display: block; }
.quality-grid span {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.quality-grid strong { margin: 6px 0 2px; font-family: var(--mono); font-size: 20px; }
.quality-grid small { color: var(--muted-2); font-size: 10px; }

.activity-list { margin: 0; padding: 0; list-style: none; }
.activity-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 11px;
  align-items: center;
  padding: 11px 18px;
  border-bottom: 1px solid var(--hair);
}
.activity-list li:last-child { border: 0; }
.activity-list strong, .activity-list small { display: block; }
.activity-list strong { font-size: 11.5px; }
.activity-list small { margin-top: 3px; color: var(--muted-2); font-size: 9.5px; }
.activity-list time { font-family: var(--mono); color: var(--muted-2); font-size: 9.5px; }
.action-notify { background: var(--green-soft); border-color: #1c4535; color: var(--green); }
.action-skip { background: var(--panel-2); color: var(--muted); }

.audit-table > div {
  display: grid;
  grid-template-columns: 140px 160px 1fr 70px 2fr;
  gap: 12px;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--hair);
  font-size: 10.5px;
}
.audit-table > div:last-child { border: 0; }
.audit-table time { font-family: var(--mono); color: var(--muted-2); }
.audit-table strong { text-transform: capitalize; color: var(--ink); }
.audit-table span, .audit-table p { margin: 0; color: var(--muted); }

.panel-empty { margin: 0; padding: 26px 20px; color: var(--muted); font-size: 12px; }

footer {
  padding: 22px 0 3px;
  text-align: center;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .1em;
  color: var(--muted-2);
}

/* ---------- Sign in ---------- */

.login-shell {
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(400px, 560px);
  min-height: 100vh;
  background: var(--bg);
}
.login-intro {
  align-self: center;
  max-width: 560px;
  padding: 64px clamp(40px, 8vw, 120px);
  color: var(--ink);
}
.login-intro .brand-mark { margin-bottom: 32px; }
.login-intro .eyebrow { color: var(--cyan); }
.login-intro h1 { margin: 0; font-size: clamp(42px, 6vw, 72px); line-height: .95; letter-spacing: -.05em; }
.intro-copy { max-width: 460px; margin: 24px 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.boundary-list { padding: 0; list-style: none; color: var(--muted); font-size: 12px; }
.boundary-list li { margin: 11px 0; }
.boundary-list li::before { content: "\203a"; margin-right: 10px; color: var(--cyan); font-family: var(--mono); }

.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: clamp(32px, 7vw, 84px);
  background: var(--panel);
  border-left: 1px solid var(--line);
}
.login-panel h2 { margin: 0; font-size: 30px; letter-spacing: -.03em; }
.login-panel .muted { font-size: 12px; }

.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.login-form input {
  width: 100%;
  margin-top: 7px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--ink);
}
.login-form .button { margin-top: 4px; padding: 12px; text-align: center; }
.optional { float: right; color: var(--muted-2); font-weight: 400; text-transform: none; letter-spacing: 0; }

.alert { padding: 11px 13px; border-radius: 7px; font-size: 11px; }
.alert-danger { border: 1px solid var(--red); background: var(--red-soft); color: #f0b3b1; }

.login-note {
  padding-top: 14px;
  border-top: 1px solid var(--hair);
  color: var(--muted-2);
  font-size: 10px;
  line-height: 1.5;
}

/* ---------- Responsive ---------- */

@media (max-width: 1040px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .banner-facts { display: none; }
  .audit-table > div { grid-template-columns: 120px 150px 1fr; }
  .audit-table p, .audit-table span:nth-of-type(2) { display: none; }
}

@media (max-width: 780px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: auto; padding: 15px; }
  .sidebar nav, .sidebar-boundary { display: none; }
  .brand { padding: 0; }
  .main { padding: 20px; }
  .topbar, .top-actions { align-items: flex-start; }
  .refresh, .profile div { display: none; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .two-column { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .global-banner { flex-direction: column; align-items: flex-start; gap: 14px; }
  .empty-state { align-items: flex-start; }
  .empty-state .badge { display: none; }
  .login-shell { display: block; }
  .login-intro { padding: 34px; }
  .login-intro h1 { font-size: 40px; }
  .intro-copy, .boundary-list { display: none; }
  .login-panel { padding: 34px; gap: 18px; border-left: 0; border-top: 1px solid var(--line); }
  .audit-table > div { grid-template-columns: 110px 1fr; }
  .audit-table span { display: none; }
}

@media (max-width: 480px) {
  .metric-grid { grid-template-columns: 1fr; }
  .quality-grid { grid-template-columns: 1fr; }
  .quality-grid > div { border-right: 0; }
  .top-actions { gap: 8px; }
  .issue-strip { flex-direction: column; }
  .issue-strip details { max-width: none; }
}
