:root {
  --bg: #071112;
  --bg-2: #0b1719;
  --card: rgba(14, 30, 32, 0.72);
  --card-solid: #0e1e20;
  --line: rgba(19, 210, 210, 0.15);
  --line-soft: rgba(19, 210, 210, 0.08);
  --text: #d9f5f3;
  --muted: #7ca9a7;
  --primary: #09dcdc;
  --primary-soft: rgba(9, 220, 220, 0.12);
  --ok: #3df08f;
  --bad: #ff6a6a;
  --warn: #ffc14d;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% -20%, rgba(0, 255, 255, 0.09), transparent 45%),
    radial-gradient(circle at 110% 10%, rgba(0, 190, 255, 0.08), transparent 40%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.top-nav {
  height: 70px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(6, 14, 15, 0.82);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-row { display: flex; align-items: center; gap: 16px; min-width: 0; }
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  color: #001112;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 0 8px rgba(9, 220, 220, 0.28);
}
.brand-text {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.brand-text span { color: var(--primary); }

.main-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
}

.main-tabs button {
  min-height: 34px;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.metric-chip {
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(13, 33, 35, 0.95);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: #9cd4d1;
}
.metric-chip.warn strong { color: var(--warn); }
.metric-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 0 10px var(--primary);
}
.stamp {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 70px);
}

.sidebar {
  display: grid;
  gap: 12px;
  align-content: start;
  overflow: auto;
  padding-right: 2px;
}

.panel {
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(12px);
  border-radius: 12px;
  padding: 12px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02), 0 4px 14px rgba(4, 20, 21, 0.32);
}
.panel h3 {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--primary);
  font-size: 11px;
}

.telemetry-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.telemetry-row strong { color: var(--primary); font-weight: 600; }
.meter {
  height: 6px;
  border-radius: 999px;
  background: rgba(9, 220, 220, 0.08);
  margin-bottom: 9px;
  overflow: hidden;
}
.meter span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, rgba(9,220,220,0.7), rgba(9,220,220,1));
  box-shadow: 0 0 5px rgba(9,220,220,0.35);
}

.auth-panel input {
  width: 100%;
  margin-bottom: 8px;
}

.auth-actions,
.macro-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.workspace {
  min-width: 0;
  overflow: auto;
  display: grid;
  gap: 12px;
}

.terminal-shell {
  padding: 0;
  overflow: hidden;
}

.shell-header {
  height: 40px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(9, 20, 21, 0.92);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 11px;
}
.lights { display: flex; gap: 6px; }
.lights span {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #2d4b4d;
}
.lights span:nth-child(1) { background: rgba(255, 108, 108, 0.6); }
.lights span:nth-child(2) { background: rgba(255, 200, 76, 0.6); }
.lights span:nth-child(3) { background: rgba(61, 240, 143, 0.6); }

.shell-title {
  font-size: 12px;
  color: #8fb3b2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shell-header .button-link { margin-left: auto; }

.shell-body {
  position: relative;
  padding: 12px;
}
.shell-body::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(255,255,255,0.012) 50%, transparent 50%);
  background-size: 100% 3px;
  pointer-events: none;
  opacity: 0.18;
}

.table-wrap {
  position: relative;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  max-height: 58vh;
  z-index: 2;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}
thead { background: rgba(10, 26, 28, 0.96); }
th, td {
  padding: 10px 10px;
  border-bottom: 1px solid rgba(12, 77, 77, 0.45);
  text-align: left;
  font-size: 12px;
  color: #b7d8d7;
  vertical-align: top;
}
tbody tr:hover td {
  background: rgba(9, 220, 220, 0.035);
}
th {
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  position: sticky;
  top: 0;
  z-index: 1;
}
.run { white-space: normal; max-width: 260px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }

.jobs { padding: 12px; }
#jobs-list { display: grid; gap: 8px; }
.job {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 9px;
  background: rgba(8, 22, 23, 0.58);
}
.job header { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }

.assistant-shell {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 190px);
  padding: 0;
  overflow: hidden;
}

.assistant-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(7, 19, 20, 0.68);
}

.assistant-head .actions {
  flex-shrink: 0;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 18% -12%, rgba(9, 220, 220, 0.05), transparent 45%),
    rgba(6, 16, 17, 0.84);
  padding: 16px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  width: min(92%, 820px);
  border: 1px solid rgba(9, 220, 220, 0.16);
  background: rgba(12, 35, 38, 0.86);
  border-radius: 14px;
  padding: 10px 12px;
  line-height: 1.45;
  align-self: flex-start;
}

.msg.user {
  align-self: flex-end;
  background: rgba(10, 65, 73, 0.75);
  border-color: rgba(9, 220, 220, 0.3);
}

.msg.assistant-working {
  opacity: 0.86;
}

.msg .meta {
  color: #90b8b5;
  font-size: 11px;
  margin-bottom: 6px;
}

.msg .body p {
  margin: 0 0 8px;
}

.msg .body p:last-child {
  margin-bottom: 0;
}

.msg .body pre {
  margin: 0;
  max-height: 240px;
}

.chat-compose {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line-soft);
  background: rgba(6, 16, 17, 0.95);
}

#chat-input {
  min-height: 48px;
  max-height: 160px;
  resize: vertical;
}

.terminal-frame {
  display: block;
  width: 100%;
  height: calc(100vh - 190px);
  min-height: 560px;
  border: 0;
  background: #050e10;
}

input[type="password"], input[type="text"], textarea {
  border: 1px solid rgba(9, 220, 220, 0.2);
  background: rgba(6, 24, 25, 0.95);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  min-height: 38px;
  line-height: 1.3;
}
input:focus, textarea:focus {
  border-color: rgba(9, 220, 220, 0.45);
  box-shadow: 0 0 0 2px rgba(9, 220, 220, 0.09);
}

button, .button-link {
  border: 1px solid rgba(9, 220, 220, 0.25);
  background: linear-gradient(180deg, rgba(8, 40, 44, 0.95), rgba(7, 24, 26, 0.95));
  color: #bde8e5;
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 12px;
  min-height: 36px;
  cursor: pointer;
  text-decoration: none;
  transition: 120ms ease;
}
button:hover, .button-link:hover {
  text-decoration: none;
  border-color: rgba(9, 220, 220, 0.42);
  color: #dbffff;
  box-shadow: 0 0 6px rgba(9, 220, 220, 0.12);
}
button.active {
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: inset 0 -2px 0 rgba(9, 220, 220, 0.85);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible,
.button-link:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(9, 220, 220, 0.16);
}

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.ok { background: rgba(61, 240, 143, 0.12); color: var(--ok); }
.bad { background: rgba(255, 106, 106, 0.12); color: var(--bad); }
.warn { background: rgba(255, 193, 77, 0.12); color: var(--warn); }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; margin: 0; }
.cmd {
  margin: 4px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: #90c8c5;
}
pre {
  margin: 6px 0 0;
  max-height: 180px;
  overflow: auto;
  background: rgba(4, 17, 19, 0.85);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  color: #abd8d6;
  white-space: pre-wrap;
}

.table-wrap::-webkit-scrollbar,
.chat-log::-webkit-scrollbar,
pre::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}
.table-wrap::-webkit-scrollbar-thumb,
.chat-log::-webkit-scrollbar-thumb,
pre::-webkit-scrollbar-thumb {
  background: rgba(9, 220, 220, 0.2);
  border-radius: 999px;
}
.table-wrap::-webkit-scrollbar-track,
.chat-log::-webkit-scrollbar-track,
pre::-webkit-scrollbar-track {
  background: rgba(9, 220, 220, 0.05);
}

@media (max-width: 1280px) {
  .layout { grid-template-columns: 250px 1fr; }
}

@media (max-width: 980px) {
  .top-nav {
    height: auto;
    padding: 10px 12px;
    flex-direction: column;
    align-items: flex-start;
  }
  .brand-row {
    width: 100%;
    flex-wrap: wrap;
    gap: 10px;
  }
  .main-tabs { margin-left: 0; }
  .main-tabs button { min-height: 38px; }
  .top-right { width: 100%; justify-content: flex-start; }
  .brand-text { font-size: 18px; }

  .layout {
    height: auto;
    grid-template-columns: 1fr;
    padding: 10px;
  }
  .sidebar {
    grid-template-columns: 1fr;
  }
  .workspace { min-height: 60vh; }
  .chat-compose { grid-template-columns: 1fr; }
  .terminal-frame { height: 64vh; min-height: 420px; }
  button, .button-link { min-height: 40px; }

  body[data-tab="assistant"],
  body[data-tab="terminal"] {
    height: 100dvh;
    overflow: hidden;
  }

  body[data-tab="assistant"] .sidebar,
  body[data-tab="terminal"] .sidebar {
    display: none;
  }

  body[data-tab="assistant"] .layout,
  body[data-tab="terminal"] .layout {
    padding: 6px;
    height: calc(100dvh - 118px);
    overflow: hidden;
  }

  body[data-tab="assistant"] .workspace,
  body[data-tab="terminal"] .workspace {
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  body[data-tab="assistant"] #panel-assistant,
  body[data-tab="terminal"] #panel-terminal {
    height: 100%;
  }

  body[data-tab="assistant"] #panel-assistant .assistant-shell,
  body[data-tab="terminal"] #panel-terminal .terminal-shell {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  #panel-assistant .shell-header,
  #panel-terminal .shell-header {
    height: 38px;
    padding: 0 8px;
    gap: 6px;
  }

  #panel-assistant .lights,
  #panel-terminal .lights {
    display: none;
  }

  #panel-assistant .shell-title,
  #panel-terminal .shell-title {
    font-size: 11px;
  }

  #panel-assistant .shell-header .button-link,
  #panel-terminal .shell-header .button-link {
    min-height: 30px;
    padding: 4px 8px;
    font-size: 11px;
  }

  body[data-tab="assistant"] #panel-assistant .chat-log,
  body[data-tab="terminal"] #panel-terminal .terminal-frame {
    flex: 1;
    height: auto;
    min-height: 0;
  }

  #panel-assistant .assistant-head {
    padding: 6px 8px;
    gap: 6px;
  }

  #panel-assistant .assistant-head .muted {
    font-size: 10px;
  }

  #panel-assistant .assistant-head .actions button {
    min-height: 28px;
    padding: 3px 7px;
    font-size: 10px;
  }

  #panel-assistant .chat-log {
    padding: 8px 8px 6px;
    overscroll-behavior: contain;
  }

  #panel-assistant .chat-compose {
    padding: 6px 8px 8px;
    gap: 5px;
    position: sticky;
    bottom: 0;
    z-index: 3;
  }

  #panel-assistant #chat-input {
    min-height: 40px;
    max-height: 120px;
    font-size: 12px;
    padding: 7px 9px;
  }

  #panel-assistant #chat-send-btn {
    min-height: 34px;
    padding: 6px 10px;
  }

  #panel-assistant .msg {
    width: min(96%, 760px);
    border-radius: 12px;
    padding: 8px 10px;
  }

  #panel-assistant .msg .meta {
    font-size: 10px;
    margin-bottom: 4px;
  }
}

@media (max-width: 540px) {
  .top-nav {
    padding: 8px 10px;
    gap: 8px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .brand-text {
    font-size: 16px;
  }

  .main-tabs {
    width: 100%;
    margin-left: 0;
    gap: 4px;
  }

  .main-tabs button {
    flex: 1;
    min-height: 34px;
    padding: 5px 7px;
    font-size: 11px;
  }

  .top-right .metric-chip {
    display: none;
  }

  .top-right .stamp {
    display: none;
  }

  body[data-tab="assistant"] .layout,
  body[data-tab="terminal"] .layout {
    height: calc(100dvh - 88px);
    padding: 4px;
  }

  #panel-assistant .shell-header,
  #panel-terminal .shell-header {
    height: 34px;
    padding: 0 6px;
  }

  #panel-assistant .shell-title,
  #panel-terminal .shell-title {
    font-size: 10px;
  }

  #panel-assistant .shell-header .button-link,
  #panel-terminal .shell-header .button-link {
    min-height: 26px;
    padding: 3px 7px;
    font-size: 10px;
  }

  #panel-assistant .assistant-head {
    padding: 5px 6px;
  }

  #panel-assistant .assistant-head .muted {
    display: none;
  }

  #panel-assistant .assistant-head .actions {
    width: 100%;
  }

  #panel-assistant .assistant-head .actions button {
    flex: 1;
  }

  #panel-assistant .chat-log {
    padding: 6px 6px 4px;
    gap: 8px;
  }

  #panel-assistant .chat-compose {
    padding: 5px 6px 6px;
    gap: 4px;
  }

  #panel-assistant #chat-input {
    min-height: 38px;
    max-height: 96px;
    font-size: 12px;
  }

  #panel-assistant #chat-send-btn {
    min-height: 32px;
    font-size: 11px;
  }

  #panel-assistant .msg {
    width: 98%;
    border-radius: 10px;
    padding: 7px 9px;
  }
}
