/* ============================================================
   MiddlewareOS Enterprise — Operations Console
   Design system: control-room / instrumentation aesthetic.
   ============================================================ */

:root {
  /* Ink — deep slate, never pure black */
  --ink-0: #0a0e14;
  --ink-1: #0f141c;
  --ink-2: #141a24;
  --ink-3: #1c2330;
  --ink-4: #242c3c;
  --ink-5: #2e3848;
  --ink-6: #3a4658;

  /* Paper — text and lines */
  --paper-0: #f5f7fa;
  --paper-1: #d4dae6;
  --paper-2: #9aa3b6;
  --paper-3: #6b7488;
  --paper-4: #4a5266;

  /* Signature accent — caustic lime, used surgically */
  --accent: #c8ff5a;
  --accent-soft: #c8ff5a22;
  --accent-line: #c8ff5a44;
  --accent-glow: 0 0 0 1px var(--accent-line), 0 8px 32px -12px var(--accent-soft);

  /* Status semantics */
  --ok: #5ee2a0;
  --ok-soft: #5ee2a01a;
  --warn: #ffb84d;
  --warn-soft: #ffb84d1a;
  --crit: #ff6b6b;
  --crit-soft: #ff6b6b1a;
  --info: #6ec1ff;
  --info-soft: #6ec1ff1a;

  /* Type */
  --font-display: 'IBM Plex Sans Condensed', 'Helvetica Neue', sans-serif;
  --font-body: 'IBM Plex Sans Condensed', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'JetBrains Mono', ui-monospace, monospace;
  --font-code: 'JetBrains Mono', ui-monospace, monospace;

  /* Geometry */
  --radius-xs: 2px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-xl: 16px;

  --gut-2: 8px;
  --gut-3: 12px;
  --gut-4: 16px;
  --gut-5: 20px;
  --gut-6: 24px;
  --gut-8: 32px;
  --gut-10: 40px;
  --gut-12: 48px;

  --topbar-h: 56px;
  --sidebar-w: 240px;

  /* Shadows */
  --shadow-1: 0 1px 0 0 #00000040, 0 8px 24px -12px #00000080;
  --shadow-2: 0 1px 0 0 #00000060, 0 24px 64px -24px #000000c0;

  /* Lines */
  --line: #ffffff0d;
  --line-strong: #ffffff1a;
  --line-accent: var(--accent-line);

  /* Transitions */
  --t-fast: 120ms cubic-bezier(.2,.7,.2,1);
  --t-med: 220ms cubic-bezier(.2,.7,.2,1);
  --t-slow: 380ms cubic-bezier(.2,.7,.2,1);
}

/* RESET */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink-0);
  color: var(--paper-1);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Atmospheric backdrop */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, #1a2030 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #18221c 0%, transparent 55%),
    linear-gradient(180deg, #0a0e14 0%, #080c11 100%);
  pointer-events: none;
  z-index: 0;
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: -1px -1px;
  pointer-events: none;
  z-index: 0;
  mask-image: radial-gradient(ellipse at 50% 30%, #000 0%, transparent 80%);
  opacity: 0.4;
}

#login-screen, #app-shell { position: relative; z-index: 1; }
#login-screen[hidden], #app-shell[hidden] { display: none !important; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--gut-6);
}
.login-grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(320px, 460px);
  gap: 0;
  width: 100%;
  max-width: 880px;
  background: var(--ink-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-2);
}
.login-brand {
  background:
    linear-gradient(135deg, var(--ink-2) 0%, var(--ink-1) 100%);
  padding: var(--gut-8);
  border-right: 1px solid var(--line-strong);
  display: flex;
  flex-direction: column;
  gap: var(--gut-6);
  position: relative;
  overflow: hidden;
}
.login-brand::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 80% 20%, var(--accent-soft) 0%, transparent 50%);
  pointer-events: none;
}
.brand-mark {
  display: flex;
  gap: var(--gut-3);
  align-items: center;
  position: relative;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--paper-0);
  line-height: 1;
}
.brand-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--paper-3);
  margin-top: 4px;
}
.brand-meta {
  display: flex;
  flex-direction: column;
  gap: var(--gut-2);
  margin-top: auto;
  position: relative;
}
.meta-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
}
.meta-row span { color: var(--paper-3); }
.meta-row b { color: var(--paper-1); font-weight: 500; }
.brand-tape {
  position: absolute;
  bottom: 8px;
  left: -20px;
  right: -20px;
  display: flex;
  gap: var(--gut-2);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.3em;
  color: var(--paper-4);
  white-space: nowrap;
  animation: tape 60s linear infinite;
  opacity: 0.5;
}
@keyframes tape {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.login-panel {
  padding: var(--gut-8);
  display: flex;
  flex-direction: column;
  gap: var(--gut-5);
  background: var(--ink-1);
}
.login-head h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 28px;
  margin: var(--gut-3) 0 var(--gut-2);
  letter-spacing: -0.02em;
  color: var(--paper-0);
}
.login-head p {
  margin: 0;
  color: var(--paper-3);
  font-size: 13px;
}
.login-foot {
  margin-top: auto;
  padding-top: var(--gut-4);
  border-top: 1px solid var(--line);
}
.login-foot small {
  color: var(--paper-4);
  font-size: 11px;
  letter-spacing: 0.02em;
}

/* ============================================================
   APP SHELL — grid layout
   ============================================================ */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
  height: 100vh;
}
.topbar { grid-area: topbar; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }

/* TOPBAR */
.topbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto minmax(280px, 1fr);
  align-items: center;
  gap: var(--gut-4);
  padding: 0 var(--gut-5);
  background: var(--ink-1);
  border-bottom: 1px solid var(--line-strong);
  position: relative;
  z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: var(--gut-5); min-width: 0; }
.topbar-mid { display: flex; justify-content: center; }
.topbar-right { display: flex; align-items: center; gap: var(--gut-3); justify-content: flex-end; }

.brand-btn {
  display: flex;
  align-items: center;
  gap: var(--gut-2);
  padding: 6px 10px 6px 6px;
  border-radius: var(--radius-md);
  transition: background var(--t-fast);
}
.brand-btn:hover { background: var(--ink-3); }
.brand-btn span {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--paper-0);
  letter-spacing: -0.01em;
}
.brand-btn em {
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 0.1em;
  background: var(--accent-soft);
  padding: 2px 5px;
  border-radius: var(--radius-xs);
}

.crumb {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--paper-3);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}
.crumb b { color: var(--paper-1); font-weight: 500; }
.crumb i { font-style: normal; color: var(--paper-4); }

/* STATUS RAIL */
.status-rail {
  display: flex;
  gap: 4px;
  background: var(--ink-2);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
}
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--paper-3);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.status-chip i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--paper-4);
  flex-shrink: 0;
}
.status-chip.ok { color: var(--paper-1); }
.status-chip.ok i { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status-chip.warn { color: var(--warn); }
.status-chip.warn i { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.status-chip.crit { color: var(--crit); }
.status-chip.crit i { background: var(--crit); box-shadow: 0 0 8px var(--crit); animation: pulse 1.2s ease-in-out infinite; }
.status-chip.off i { background: var(--paper-4); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* USER POD */
.user-pod {
  display: flex;
  align-items: center;
  gap: var(--gut-2);
  padding: 4px;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  position: relative;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--ink-0);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0;
}
.user-info { display: flex; flex-direction: column; line-height: 1.2; padding-right: 4px; }
.user-name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 13px;
  color: var(--paper-0);
}
.user-role {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--paper-3);
  text-transform: uppercase;
}
.user-menu-btn {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--paper-3);
  transition: background var(--t-fast);
}
.user-menu-btn:hover { background: var(--ink-3); color: var(--paper-1); }
.user-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--ink-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 4px;
  min-width: 160px;
  box-shadow: var(--shadow-2);
  z-index: 20;
}
.user-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--paper-1);
  transition: background var(--t-fast);
}
.user-menu button:hover { background: var(--ink-3); }

/* SIDEBAR */
.sidebar {
  background: var(--ink-1);
  border-right: 1px solid var(--line-strong);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.nav { flex: 1; overflow-y: auto; padding: var(--gut-3) var(--gut-2); }
.nav::-webkit-scrollbar { width: 4px; }
.nav::-webkit-scrollbar-thumb { background: var(--ink-4); border-radius: 2px; }
.nav-group { margin-bottom: var(--gut-4); }
.nav-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--paper-4);
  text-transform: uppercase;
  padding: 6px 12px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--paper-2);
  text-align: left;
  transition: all var(--t-fast);
  position: relative;
}
.nav-item:hover { background: var(--ink-3); color: var(--paper-0); }
.nav-item.active {
  background: var(--ink-3);
  color: var(--accent);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.nav-icon {
  font-family: var(--font-mono);
  font-size: 14px;
  width: 16px;
  text-align: center;
  color: var(--paper-4);
  flex-shrink: 0;
}
.nav-item.active .nav-icon { color: var(--accent); }
.nav-shortcut {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--paper-4);
  font-style: normal;
}
.nav-badge {
  margin-left: auto;
  background: var(--crit);
  color: var(--ink-0);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 99px;
  min-width: 18px;
  text-align: center;
}
.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: var(--gut-3) var(--gut-4);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sf-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
}
.sf-row span { color: var(--paper-4); }
.sf-row b { color: var(--paper-2); font-weight: 500; }

/* MAIN */
.main {
  overflow-y: auto;
  position: relative;
}
.main::-webkit-scrollbar { width: 8px; }
.main::-webkit-scrollbar-thumb { background: var(--ink-4); border-radius: 4px; }
.main::-webkit-scrollbar-thumb:hover { background: var(--ink-5); }
.panel {
  padding: var(--gut-6) var(--gut-8);
  max-width: 1600px;
  margin: 0 auto;
  min-height: 100%;
  animation: panelIn 220ms cubic-bezier(.2,.7,.2,1);
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--gut-5);
  margin-bottom: var(--gut-6);
  padding-bottom: var(--gut-4);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.panel-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.panel-title .eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-transform: uppercase;
}
.panel-title h1 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--paper-0);
}
.panel-title p { margin: 4px 0 0; color: var(--paper-3); font-size: 13px; max-width: 60ch; }
.panel-actions { display: flex; gap: var(--gut-2); flex-wrap: wrap; }

/* AI DRAWER */
.ai-drawer {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: min(420px, 92vw);
  background: var(--ink-1);
  border-left: 1px solid var(--line-strong);
  display: flex;
  flex-direction: column;
  z-index: 50;
  box-shadow: -24px 0 64px -24px #000000c0;
  animation: drawerIn 220ms cubic-bezier(.2,.7,.2,1);
}
@keyframes drawerIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.ai-drawer[hidden] { display: none; }
.ai-head {
  padding: var(--gut-4) var(--gut-5);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--gut-3);
}
.ai-head h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  margin: 6px 0 0;
  color: var(--paper-0);
}
.ai-actions { display: flex; gap: 4px; }
.ai-stream {
  flex: 1;
  overflow-y: auto;
  padding: var(--gut-4) var(--gut-5);
  display: flex;
  flex-direction: column;
  gap: var(--gut-3);
}
.ai-msg { display: flex; flex-direction: column; gap: 4px; }
.ai-msg-meta {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.15em;
  color: var(--paper-4);
  text-transform: uppercase;
}
.ai-msg-body {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.ai-msg.user .ai-msg-body { background: var(--ink-3); border-color: var(--ink-5); }
.ai-msg.assistant .ai-msg-body { background: linear-gradient(180deg, var(--ink-2), var(--ink-1)); }
.ai-msg.system .ai-msg-body {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
}
.ai-msg .actions-block {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-action-card {
  background: var(--ink-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ai-action-card .ac-title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--paper-1);
}
.ai-action-card .ac-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--paper-3);
}
.ai-action-card .ac-meta .risk { padding: 1px 6px; border-radius: 2px; margin-left: 4px; }
.ai-action-card .risk-low { background: var(--ok-soft); color: var(--ok); }
.ai-action-card .risk-medium { background: var(--info-soft); color: var(--info); }
.ai-action-card .risk-high { background: var(--warn-soft); color: var(--warn); }
.ai-action-card .risk-critical { background: var(--crit-soft); color: var(--crit); }

.ai-form {
  padding: var(--gut-3) var(--gut-5);
  border-top: 1px solid var(--line);
  display: flex;
  gap: var(--gut-2);
  align-items: flex-end;
}
.ai-form textarea {
  flex: 1;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--paper-0);
  resize: none;
  outline: none;
  transition: border-color var(--t-fast);
}
.ai-form textarea:focus { border-color: var(--accent-line); }
.ai-foot {
  padding: 8px var(--gut-5);
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  color: var(--paper-4);
  text-align: center;
}

/* SCROLLBARS in drawer */
.ai-stream::-webkit-scrollbar { width: 4px; }
.ai-stream::-webkit-scrollbar-thumb { background: var(--ink-4); border-radius: 2px; }

/* Responsive */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 56px 1fr; }
  .sidebar { width: 56px; }
  .nav-item span:not(.nav-icon), .nav-shortcut, .nav-label, .nav-badge, .sidebar-foot { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .topbar { grid-template-columns: 1fr auto; }
  .topbar-mid { display: none; }
  .panel { padding: var(--gut-4); }
  .login-grid { grid-template-columns: 1fr; }
  .login-brand { display: none; }
}
