/* Cerberus — painel interno de instâncias de IA
   Dark mode único (sem tema claro: é um painel técnico de comando). */

:root {
  --bg: #08080c;
  --bg-elevated: #0f0f16;
  --surface: #14141d;
  --surface-2: #191924;
  --border: #262632;
  --border-soft: #1c1c27;
  --text: #e9e9f2;
  --text-dim: #9d9db0;
  --text-faint: #6b6b80;
  --accent: #5fb3ff;
  --accent-dim: #3d7fb8;
  --ok: #34d399;
  --error: #f87171;
  --warn: #fbbf24;
  --off: #5c5c6e;

  --k-claude: #d97757;
  --k-codex: #10a37f;
  --k-agy: #8b7cf6;
  --k-groq: #ef4470;

  --radius: 10px;
  --radius-sm: 6px;
  --mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

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

[hidden] { display: none !important; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

a { color: var(--accent); }

::selection {
  background: rgba(95, 179, 255, 0.28);
}

/* ---------- layout shell ---------- */

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

.navbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 20;
}

.navbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 15px;
  white-space: nowrap;
}

.navbar__brand .dot3 {
  display: inline-flex;
  gap: 2px;
}
.navbar__brand .dot3 span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}
.navbar__brand .dot3 span:nth-child(2) { background: var(--k-codex); }
.navbar__brand .dot3 span:nth-child(3) { background: var(--k-agy); }

.navbar__nav {
  display: flex;
  gap: 4px;
}

.navlink {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: background .12s, color .12s;
}
.navlink:hover { color: var(--text); background: var(--surface); }
.navlink.active { color: var(--text); background: var(--surface-2); }

.navbar__spacer { flex: 1; }

.navbar__wallet {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-dim);
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}
.navbar__wallet strong { color: var(--text); font-weight: 600; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); border-color: #34344a; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #051018;
  font-weight: 600;
}
.btn-primary:hover { background: #78c0ff; border-color: #78c0ff; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover { background: var(--surface); color: var(--text); }

.btn-danger { color: var(--error); }

.btn-sm { padding: 4px 10px; font-size: 12.5px; }

main {
  flex: 1;
  width: 100%;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.page__header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.page__title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.page__subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 2px;
}

/* ---------- login ---------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}

.login-card__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  margin-bottom: 4px;
}

.login-card__sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 26px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 500;
}

.field input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .12s;
}
.field input:focus { border-color: var(--accent); }

.field input.otp-input {
  font-family: var(--mono);
  font-size: 20px;
  letter-spacing: 0.4em;
  text-align: center;
  padding-left: 6px;
}

.login-card form { display: flex; flex-direction: column; }

.login-card__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.login-card__hint {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 14px;
  text-align: center;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12.5px;
  padding: 0;
}
.link-btn:disabled { color: var(--text-faint); cursor: default; }

/* ---------- instance grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color .12s, transform .12s;
  text-align: left;
}

.instance-card {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.instance-card:hover {
  border-color: #34344a;
  transform: translateY(-1px);
}

.instance-card__top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.kind-badge {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  color: #0b0b10;
  flex-shrink: 0;
}

.instance-card__names {
  min-width: 0;
  flex: 1;
}

.instance-card__display {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.instance-card__slug {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--off);
}
.status-dot.status-ok { background: var(--ok); box-shadow: 0 0 8px rgba(52,211,153,.7); }
.status-dot.status-error { background: var(--error); box-shadow: 0 0 8px rgba(248,113,113,.6); }

.instance-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
}

.instance-card__model {
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 62%;
}

.instance-card__status-label {
  display: flex;
  align-items: center;
  gap: 6px;
  text-transform: capitalize;
}

.empty-state {
  color: var(--text-faint);
  padding: 40px 0;
  text-align: center;
}

/* ---------- instance detail ---------- */

.detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.detail-header__kind {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  color: #0b0b10;
  flex-shrink: 0;
}

.detail-header__names { min-width: 0; flex: 1; }

.detail-header__display {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.detail-header__slug {
  font-family: var(--mono);
  color: var(--text-faint);
  font-size: 12.5px;
}

.detail-header__badges {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.pill {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.tab {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 9px 16px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- terminal ---------- */

.term-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.term-toolbar .status-dot { width: 7px; height: 7px; }

.term-wrap {
  background: #0a0a10;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  height: 62vh;
  min-height: 360px;
}

.term-container {
  width: 100%;
  height: 100%;
}

/* ---------- config tab ---------- */

.config-form {
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.config-form .field input {
  font-family: var(--mono);
}

/* ---------- files tab ---------- */

.files-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 18px;
  align-items: start;
}

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

.files-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.files-panel h4 {
  margin: 0 0 8px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 600;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-family: var(--mono);
  font-size: 12.5px;
  width: 100%;
}
.file-row:hover { background: var(--surface-2); }
.file-row.active { background: var(--surface-2); color: var(--accent); }
.file-row .icon { color: var(--text-faint); flex-shrink: 0; }

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
  margin: 10px 0 8px;
}
.breadcrumb button {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-family: var(--mono);
  font-size: 11.5px;
}

.editor-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 420px;
  display: flex;
  flex-direction: column;
}

.editor-panel__header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.editor-panel__path {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  flex: 1;
  overflow-wrap: anywhere;
}

.editor-panel__dirty {
  color: var(--warn);
  font-size: 11px;
}

.editor-panel textarea {
  flex: 1;
  min-height: 380px;
  background: #0a0a10;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  resize: vertical;
  outline: none;
}
.editor-panel textarea:focus { border-color: var(--accent); }

.editor-panel__actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.editor-empty {
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 380px;
  text-align: center;
  font-size: 13px;
}

/* ---------- usage page ---------- */

.usage-grid {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 16px;
  margin-bottom: 22px;
}

@media (max-width: 860px) {
  .usage-grid { grid-template-columns: 1fr; }
}

.wallet-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.wallet-card__label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.wallet-card__value {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
}

.wallet-card__updated {
  color: var(--text-faint);
  font-size: 12px;
  margin-top: 6px;
}

.hours-toggle {
  display: flex;
  gap: 6px;
}

.hours-toggle button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #051018;
  font-weight: 600;
}

.section-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.section-block__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-block__title h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.usage-row {
  display: grid;
  grid-template-columns: 150px 90px 1fr 100px 30px;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 12.5px;
}
.usage-row:last-child { border-bottom: none; }

.usage-row__name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  min-width: 0;
}
.usage-row__name span.slugtext {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.usage-bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.usage-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.usage-row__value {
  font-family: var(--mono);
  text-align: right;
  color: var(--text-dim);
}

.usage-row__expand {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 14px;
  text-align: center;
}
.usage-row__expand:hover { color: var(--accent); }

.usage-submodels {
  grid-column: 1 / -1;
  padding: 6px 0 10px 20px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.usage-submodels__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.data-table th {
  text-align: left;
  color: var(--text-faint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10.5px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

table.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--mono);
  color: var(--text-dim);
}

table.data-table tr:last-child td { border-bottom: none; }

.amount-pos { color: var(--ok); }
.amount-neg { color: var(--error); }

.table-scroll {
  overflow-x: auto;
}

/* ---------- toasts ---------- */

#toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  max-width: 360px;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(0,0,0,.4);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s, transform .18s;
  cursor: pointer;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-left-color: var(--error); }
.toast-success { border-left-color: var(--ok); }
.toast-info { border-left-color: var(--accent); }

/* ---------- misc ---------- */

.spinner {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-block {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-faint);
  padding: 30px 0;
  justify-content: center;
}

.text-faint { color: var(--text-faint); }
.text-dim { color: var(--text-dim); }
