/*
 * Crusoe AI Platform console - the shell's stylesheet.
 *
 * The palette is lifted from demo/agent-studio deliberately: the two surfaces
 * are the same product and a user moving between them should not feel a change
 * of vendor. Everything is a custom property, so a page that needs a colour
 * takes it from here rather than inventing one - eight pages each choosing their
 * own "danger red" is how a console starts looking assembled rather than built.
 *
 * DENSITY IS A FEATURE. This is an operations console: rows are 34px, the type
 * is 13-14px, and padding is tight, because the job is comparing twenty things
 * at once, not reading one.
 */

:root {
  --bg: #0a0e13;
  --panel: #11161d;
  --panel-2: #161d26;
  --panel-3: #1c242f;
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .16);
  --text: #e6edf3;
  --text-dim: #8b98a5;
  --text-faint: #5c6773;
  --accent: #ff8552;
  --accent-hover: #ff9a70;
  --accent-soft: rgba(255, 133, 82, .14);
  --ok: #3ddc97;
  --ok-soft: rgba(61, 220, 151, .12);
  --warn: #ffc857;
  --warn-soft: rgba(255, 200, 87, .12);
  --err: #ff5d5d;
  --err-soft: rgba(255, 93, 93, .12);
  --info: #58a6ff;
  --info-soft: rgba(88, 166, 255, .12);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;

  --topbar-h: 52px;
  --nav-w: 232px;
  --radius: 8px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

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

::selection { background: var(--accent-soft); }

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

[hidden] { display: none !important; }

/* Focus is always visible. An operations console is used from the keyboard more
   than its designers expect, and a focus ring removed "for looks" makes half of
   it unusable. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

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

.login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(255, 133, 82, .10), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand h1 { font-size: 17px; font-weight: 650; letter-spacing: .2px; }
.login-brand p { font-size: 13px; color: var(--text-dim); }

.login-mark, .brand-mark {
  width: 26px; height: 26px; flex: none; border-radius: 7px;
  background: linear-gradient(140deg, var(--accent), #d9532a);
  box-shadow: 0 0 18px rgba(255, 133, 82, .35);
}

.login-card label { font-size: 12px; color: var(--text-dim); margin-top: 8px; }

.login-error {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--err-soft);
  border: 1px solid rgba(255, 93, 93, .35);
  color: #ffb3b3;
  font-size: 13px;
}

.login-note {
  margin-top: 14px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-faint);
}

/* --------------------------------------------------------------------------
   Application shell
   -------------------------------------------------------------------------- */

.app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #10151c, #0c1117);
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; flex: none; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; }
.brand-name { font-weight: 650; font-size: 14.5px; letter-spacing: .2px; white-space: nowrap; }

.topbar-spacer { flex: 1; min-width: 0; }

.scope {
  display: flex; align-items: center; gap: 10px;
  height: 32px; padding: 0 12px;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text);
  font: inherit; font-size: 13px;
  cursor: pointer;
  max-width: 420px;
}
.scope:hover { background: var(--panel-3); }
.scope-label { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; flex: none; }
.scope-value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scope-caret {
  flex: none; width: 0; height: 0;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid var(--text-faint);
}

.user-chip {
  display: flex; align-items: center; gap: 9px;
  height: 34px; padding: 0 10px 0 6px;
  background: transparent; border: 1px solid transparent; border-radius: 999px;
  color: var(--text); font: inherit; cursor: pointer;
}
.user-chip:hover { background: var(--panel-2); border-color: var(--border); }
.user-avatar {
  width: 24px; height: 24px; flex: none; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
}
.user-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; min-width: 0; }
.user-email { font-size: 12.5px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .5px; }

@media (max-width: 860px) {
  .brand-name { display: none; }
  .user-meta { display: none; }
}

.menu {
  position: absolute; top: calc(var(--topbar-h) - 4px); right: 12px;
  min-width: 190px; padding: 5px;
  background: var(--panel-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
  z-index: 40;
}
.menu-item {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
}
.menu-item:hover { background: var(--panel-3); }

.shell { flex: 1; display: flex; min-height: 0; }

/* --------------------------------------------------------------------------
   Left navigation
   -------------------------------------------------------------------------- */

.nav {
  width: var(--nav-w); flex: none;
  border-right: 1px solid var(--border);
  background: #0d1219;
  overflow-y: auto;
  padding: 12px 8px 24px;
}

.nav-section {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-faint); padding: 14px 10px 6px;
}
.nav-section:first-child { padding-top: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; margin-bottom: 1px;
  border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 13.5px;
  cursor: pointer;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.nav-item.disabled { opacity: .38; pointer-events: none; }
.nav-icon { width: 18px; text-align: center; flex: none; font-size: 14px; }
.nav-hint { padding: 8px 12px; font-size: 12px; color: var(--text-faint); line-height: 1.45; }

/* --------------------------------------------------------------------------
   Content column
   -------------------------------------------------------------------------- */

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

.crumbs {
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 18, 25, .6);
}

.breadcrumb { display: flex; align-items: center; gap: 7px; list-style: none; min-width: 0; flex: 1; }
.breadcrumb li { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-dim); white-space: nowrap; }
.breadcrumb li + li::before { content: "/"; color: var(--text-faint); }
.breadcrumb li:last-child { color: var(--text); font-weight: 550; }

.page-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.page { flex: 1; min-height: 0; overflow-y: auto; padding: 22px; }
.page:focus { outline: none; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.page-head h2 { font-size: 19px; font-weight: 620; letter-spacing: .2px; }
.page-head p { font-size: 13px; color: var(--text-dim); margin-top: 3px; max-width: 74ch; }
.page-head .spacer { flex: 1; }

.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.section-head h3 { font-size: 14px; font-weight: 600; }
.section-head .spacer { flex: 1; }
.section-head p { font-size: 12.5px; color: var(--text-dim); }

/* --------------------------------------------------------------------------
   Buttons and inputs
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 32px; padding: 0 13px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--panel-2); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--panel-3); border-color: rgba(255, 255, 255, .24); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #150b06; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: #ffb3b3; border-color: rgba(255, 93, 93, .4); background: var(--err-soft); }
.btn-danger:hover:not(:disabled) { background: rgba(255, 93, 93, .2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.btn-sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 18px; height: 36px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
select, textarea {
  width: 100%; height: 34px; padding: 0 11px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit; font-size: 13.5px;
}
textarea { height: auto; min-height: 90px; padding: 9px 11px; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }
select { appearance: none; padding-right: 28px; cursor: pointer; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); }

/* --------------------------------------------------------------------------
   Forms (CAI.ui.form)
   -------------------------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field > label { font-size: 12px; color: var(--text-dim); }
.form-field .help { font-size: 11.5px; color: var(--text-faint); line-height: 1.45; }
.form-field.inline { flex-direction: row; align-items: center; gap: 9px; }
.form-field.inline > label { order: 2; color: var(--text); font-size: 13px; }
.form-field .field-error { font-size: 11.5px; color: #ffb3b3; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.form-error {
  padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--err-soft); border: 1px solid rgba(255, 93, 93, .35);
  color: #ffb3b3; font-size: 12.5px;
}

/* --------------------------------------------------------------------------
   Tables (CAI.ui.table)
   -------------------------------------------------------------------------- */

.table-wrap {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); overflow: hidden;
}
.table-scroll { overflow-x: auto; }

table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.table th {
  text-align: left; font-weight: 550; font-size: 11px;
  text-transform: uppercase; letter-spacing: .6px; color: var(--text-faint);
  padding: 9px 14px; background: var(--panel-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.table td {
  padding: 0 14px; height: 34px;
  border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
table.table tbody tr:last-child td { border-bottom: 0; }
table.table tbody tr.clickable { cursor: pointer; }
table.table tbody tr.clickable:hover { background: var(--panel-2); }
table.table td.mono, .mono { font-family: var(--mono); font-size: 12px; }
table.table td.dim { color: var(--text-dim); }
table.table td.actions { text-align: right; white-space: nowrap; }
table.table td.actions .btn + .btn { margin-left: 6px; }
table.table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   State blocks: loading / empty / error. One look for all of them, everywhere.
   -------------------------------------------------------------------------- */

.state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 42px 24px; text-align: center;
  color: var(--text-dim); font-size: 13px;
}
.state h4 { font-size: 14px; font-weight: 600; color: var(--text); }
.state p { max-width: 56ch; line-height: 1.5; }
.state .state-icon { font-size: 24px; opacity: .6; }
.state.error { color: #ffb3b3; }
.state.error h4 { color: #ffd0d0; }
.state .request-id { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .3px;
  background: var(--panel-3); color: var(--text-dim);
  border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: rgba(61, 220, 151, .3); }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(255, 200, 87, .3); }
.badge.err { background: var(--err-soft); color: var(--err); border-color: rgba(255, 93, 93, .3); }
.badge.info { background: var(--info-soft); color: var(--info); border-color: rgba(88, 166, 255, .3); }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: rgba(255, 133, 82, .3); }

/* --------------------------------------------------------------------------
   Modals (CAI.ui.modal / CAI.ui.confirm)
   -------------------------------------------------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(4, 7, 10, .68);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 20px 24px;
  overflow-y: auto;
}
.modal {
  width: 100%; max-width: 480px;
  background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}
.modal.wide { max-width: 720px; }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 15px; font-weight: 600; flex: 1; }
.modal-close {
  width: 26px; height: 26px; flex: none; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-dim); font-size: 17px; line-height: 1; cursor: pointer;
}
.modal-close:hover { background: var(--panel-3); color: var(--text); }
.modal-body { padding: 18px; }
.modal-body p { font-size: 13.5px; color: var(--text-dim); line-height: 1.55; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 18px; border-top: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   Toasts (CAI.ui.toast)
   -------------------------------------------------------------------------- */

.toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 80;
  display: flex; flex-direction: column-reverse; gap: 9px;
  max-width: min(420px, calc(100vw - 36px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 13px;
  background: var(--panel-2); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--text-faint);
  border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  font-size: 13px; line-height: 1.45;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
.toast.info { border-left-color: var(--info); }
.toast-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-detail { display: block; margin-top: 3px; font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }
.toast-close {
  border: 0; background: transparent; color: var(--text-faint);
  font-size: 15px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.toast-close:hover { color: var(--text); }

/* --------------------------------------------------------------------------
   Show-once secret (CAI.ui.copyOnce)
   -------------------------------------------------------------------------- */

.copy-once {
  border: 1px solid rgba(255, 200, 87, .35);
  background: var(--warn-soft);
  border-radius: var(--radius);
  padding: 13px 14px;
}
.copy-once .copy-once-label { font-size: 12px; color: var(--warn); font-weight: 600; margin-bottom: 7px; }
.copy-once .copy-once-row { display: flex; align-items: center; gap: 8px; }
.copy-once code {
  flex: 1; min-width: 0;
  font-family: var(--mono); font-size: 12px;
  background: rgba(0, 0, 0, .35); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 9px;
  overflow-x: auto; white-space: nowrap;
}
.copy-once .copy-once-note { margin-top: 8px; font-size: 11.5px; color: var(--text-dim); line-height: 1.45; }

/* --------------------------------------------------------------------------
   Scope picker
   -------------------------------------------------------------------------- */

.scope-picker { display: flex; flex-direction: column; gap: 14px; }
.scope-list { border: 1px solid var(--border); border-radius: var(--radius); max-height: 320px; overflow-y: auto; }
.scope-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border: 0; border-bottom: 1px solid var(--border);
  background: transparent; color: var(--text); font: inherit; font-size: 13px;
  text-align: left; cursor: pointer;
}
.scope-row:last-child { border-bottom: 0; }
.scope-row:hover { background: var(--panel-2); }
.scope-row.selected { background: var(--accent-soft); color: var(--accent); }
.scope-row .scope-row-meta { margin-left: auto; font-size: 11.5px; color: var(--text-faint); font-family: var(--mono); }

/* --------------------------------------------------------------------------
   Small shared utilities. Kept short on purpose: a utility framework grown in a
   stylesheet nobody owns is how the next page ends up with its own.
   -------------------------------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.notice {
  border: 1px solid var(--border-strong); background: var(--panel-2);
  border-left: 3px solid var(--info); border-radius: var(--radius);
  padding: 11px 13px; font-size: 12.5px; color: var(--text-dim); line-height: 1.55;
}
.notice.warn { border-left-color: var(--warn); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 13px; }
.kv dt { color: var(--text-faint); font-size: 12px; }
.kv dd { color: var(--text); overflow-wrap: anywhere; }
