/* ---------------------------------------------------------------------------
   Agent Terminal — minimal dark UI.
   Near-monochrome zinc palette, hairline borders, generous whitespace. Colour
   is reserved for status, so a red dot or an amber quota warning actually
   reads as a signal instead of blending into decoration.
--------------------------------------------------------------------------- */
:root {
  --bg: #09090b;
  --bg-panel: #0b0b0d;
  --bg-raised: #18181b;
  --bg-hover: #141417;
  --border: #27272a;
  --border-strong: #3f3f46;
  --text: #fafafa;
  --text-dim: #a1a1aa;
  --text-faint: #71717a;
  --accent: #fafafa;
  --accent-fg: #09090b;
  --accent-dim: #e4e4e7;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 6px;
  --radius-lg: 10px;
  /* System stack only — no webfont is vendored, and the app must work offline. */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, sans-serif;
  --font-mono: "SFMono-Regular", Menlo, Consolas, monospace;
  --ring: 0 0 0 1px var(--border-strong);
  --shadow-lg: 0 16px 48px -12px rgba(0, 0, 0, .7);
  --ease: cubic-bezier(.4, 0, .2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13.5px;
  line-height: 1.5;
  letter-spacing: -.011em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: #3f3f46; color: var(--text); }

/* Scrollbars stay out of the way until you look for them. */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #27272a; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

.hidden { display: none !important; }
.muted { color: var(--text-dim); }
.error {
  color: var(--red);
  min-height: 17px;
  margin: 2px 0 0;
  font-size: 12.5px;
}

/* ---------- controls ---------- */
input, select, button, textarea {
  font-family: inherit;
  font-size: 13.5px;
  letter-spacing: inherit;
}
input, select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 11px;
  width: 100%;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input::placeholder { color: var(--text-faint); }
input:hover, select:hover { border-color: var(--border-strong); }
input:focus, select:focus {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(250, 250, 250, .07);
}

button {
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: background .15s var(--ease), border-color .15s var(--ease),
              color .15s var(--ease), opacity .15s var(--ease);
}
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--border-strong);
}

/* Inverted primary: white on black, the one deliberate high-contrast element. */
.primary-btn {
  background: var(--accent);
  color: var(--accent-fg);
  padding: 8px 14px;
  font-weight: 500;
}
.primary-btn:hover { background: var(--accent-dim); }
.primary-btn:active { transform: translateY(.5px); }

.ghost-btn {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
  padding: 8px 14px;
  font-weight: 450;
}
.ghost-btn:hover { background: var(--bg-raised); border-color: var(--border-strong); }

.icon-btn {
  background: transparent;
  color: var(--text-faint);
  border: none;
  border-radius: 5px;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.icon-btn:hover { color: var(--text); background: var(--bg-raised); }
.icon-btn svg { width: 14px; height: 14px; display: block; }
.icon-btn.danger:hover { color: var(--red); }

/* ---------- login ---------- */
.login-screen {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  /* A single soft pool of light behind the card, nothing more. */
  background:
    radial-gradient(60% 50% at 50% 0%, rgba(255, 255, 255, .035), transparent 70%),
    var(--bg);
}
.login-card {
  width: 340px;
  padding: 32px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-card h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -.02em;
}
.login-card > p {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-dim);
}
.login-card button[type=submit] { margin-top: 6px; }

/* ---------- layout ---------- */
.app { display: flex; height: 100%; }

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
}
.brand {
  font-weight: 600;
  font-size: 13.5px;
  letter-spacing: -.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text);
  flex-shrink: 0;
}

.account-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 12px 14px;
  padding: 9px 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.account-info { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.account-name {
  font-size: 12.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-role {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: lowercase;
}
.account-actions { display: flex; gap: 1px; flex-shrink: 0; }

.sidebar-actions { padding: 0 12px 14px; display: grid; gap: 7px; }
.sidebar-actions button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.sidebar-actions button svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: .75;
}
.sidebar-actions button:disabled {
  opacity: .4;
  cursor: not-allowed;
}
.primary-btn:disabled:hover { background: var(--accent); }
.ghost-btn:disabled:hover { background: transparent; border-color: var(--border); }

.session-quota {
  margin: 1px 0 0;
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.45;
}
.session-quota.full { color: var(--amber); }

.session-list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px 8px;
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
}
.badge {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 10.5px;
  letter-spacing: 0;
  color: var(--text-dim);
}

.session-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 8px;
  overflow-y: auto;
  flex: 1;
}
.session-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 1px;
  position: relative;
  transition: background .12s var(--ease);
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: var(--bg-raised); }
/* A hairline rail rather than a coloured bar — the active row is already darker. */
.session-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 2px;
  border-radius: 999px;
  background: var(--text);
}
.session-item .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.session-item.running .dot { background: var(--green); }
.session-item.starting .dot { background: var(--amber); }
.session-item.exited .dot { background: var(--red); }
.session-item .info { flex: 1; min-width: 0; }
.session-item .name {
  display: block;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-item .sub {
  display: block;
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-item .actions { display: none; gap: 1px; }
.session-item:hover .actions, .session-item.active .actions { display: flex; }

.sidebar-foot {
  padding: 11px 16px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
}
.conn-state {
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 7px;
}
.conn-state::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.conn-state.online { color: var(--green); }
.conn-state.offline { color: var(--red); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  overflow-x: auto;
  scrollbar-width: none;
}
.topbar::-webkit-scrollbar { display: none; }
.tabs { display: flex; min-height: 41px; padding: 0 6px; align-items: center; gap: 2px; }
.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  height: 29px;
  border-radius: var(--radius);
  color: var(--text-faint);
  cursor: pointer;
  white-space: nowrap;
  max-width: 200px;
  font-size: 12.5px;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.tab:hover { background: var(--bg-hover); color: var(--text-dim); }
.tab.active { color: var(--text); background: var(--bg-raised); }
.tab .tab-name { overflow: hidden; text-overflow: ellipsis; }
.tab .close { opacity: 0; padding: 2px; }
.tab:hover .close, .tab.active .close { opacity: 1; }

.terminal-area { flex: 1; position: relative; min-height: 0; background: var(--bg); }
#terminals { position: absolute; inset: 0; }
.term-pane { position: absolute; inset: 0; padding: 10px 12px; display: none; }
.term-pane.active { display: block; }
.term-pane > div { width: 100%; height: 100%; }

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--text-faint);
  padding: 24px;
}
.empty-state h2 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: -.01em;
}
.empty-state p { margin: 0; font-size: 12.5px; max-width: 320px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 9, 11, .72);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 24px;
  animation: fade .15s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px) scale(.985); } }

.modal {
  width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  animation: rise .18s var(--ease);
}
#users-modal { width: 560px; }

.modal h2 {
  margin: 0 0 3px;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -.015em;
}
.modal label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-dim);
}
.modal label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 450;
}
.modal label.checkbox input { width: auto; accent-color: var(--text); }
.modal .row { display: flex; gap: 10px; }
.modal .row .grow { flex: 1; }
.modal .row .narrow { width: 88px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ---------- account table ---------- */
.users-table { display: flex; flex-direction: column; gap: 5px; }
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .12s var(--ease);
}
.user-row:hover { border-color: var(--border-strong); }
.user-row.disabled { opacity: .5; }
.user-info { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.user-name {
  font-size: 12.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-sub { font-size: 11px; color: var(--text-faint); }
.user-actions { display: flex; gap: 1px; flex-shrink: 0; }

@media (max-width: 720px) {
  .sidebar { width: 208px; }
  .modal, #users-modal { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
