/* V1Ron Dev Panel — matches v1ron-os design system */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=Space+Mono:wght@400;700&display=swap');

:root {
  --bg: #04020a;
  --surface: #0e0a1a;
  --surface2: #161028;
  --surface3: #1e1840;
  --border: rgba(139,92,246,0.2);
  --border-active: rgba(167,139,250,0.45);
  --accent: #8b5cf6;
  --accent2: #a78bfa;
  --accent-dim: #6d28d9;
  --accent-glow: rgba(139,92,246,0.35);
  --a-glow: rgba(139,92,246,0.18);
  --glow-sm: 0 0 12px rgba(139,92,246,0.35);
  --glow-md: 0 0 24px rgba(139,92,246,0.45);
  --text: #f0ecff;
  --text2: #9d8cc5;
  --text3: #4d3f6b;
  --font: 'Space Grotesk', sans-serif;
  --font-mono: 'Space Mono', monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  /* Structural — overridden in bright mode */
  --input-bg:      rgba(22,16,40,0.8);
  --panel-bg:      rgba(14,10,26,0.97);
  --auth-card-bg:  rgba(14,10,26,0.92);
  --glass-overlay: rgba(255,255,255,0.07);
  --glass-hover:   rgba(255,255,255,0.12);
  --overlay-bg:    rgba(0,0,0,0.7);
}

/* ── Bright mode ──────────────────────────────────────────────── */
body.bright-mode {
  background: radial-gradient(ellipse 80% 60% at 50% 30%, #e8e0ff 0%, #f5f3ff 65%) !important;
  /* core colour tokens — flip the dark palette to light */
  --bg:            #f5f3ff;
  --surface:       rgba(255,255,255,0.97);
  --surface2:      rgba(236,228,255,0.85);
  --surface3:      rgba(220,210,255,0.70);
  --border:        rgba(139,92,246,0.25);
  --border-active: rgba(139,92,246,0.50);
  --text:          #1a1040;
  --text2:         #4a3880;
  --text3:         #8070aa;
  /* structural */
  --input-bg:      rgba(255,255,255,0.9);
  --panel-bg:      rgba(255,255,255,0.97);
  --auth-card-bg:  rgba(255,255,255,0.95);
  --glass-overlay: rgba(0,0,0,0.05);
  --glass-hover:   rgba(0,0,0,0.10);
  --overlay-bg:    rgba(0,0,0,0.40);
}
body.bright-mode .auth-card  { background: var(--auth-card-bg); }
body.bright-mode .card       { background: var(--panel-bg); border-color: rgba(139,92,246,0.15); }
body.bright-mode .modal-backdrop { background: var(--overlay-bg); }
body.bright-mode select option   { background: #fff; color: #1a1040; }
/* hardcoded-bg overrides for bright mode */
body.bright-mode .topbar {
  background: rgba(245,243,255,0.97);
}
body.bright-mode .instance-card {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
}
body.bright-mode .modal {
  background: var(--surface);
}
body.bright-mode .toast-item {
  background: var(--surface);
}
/* ── Bright mode: status/role/alert colours ───────────────────── */
/* Running → dark green */
body.bright-mode .status-running {
  background: rgba(5,150,105,.10); color: #065f46; border-color: rgba(5,150,105,.30);
}
/* Stopped → dark slate */
body.bright-mode .status-stopped {
  background: rgba(100,116,139,.10); color: #334155; border-color: rgba(100,116,139,.25);
}
/* Pending / provisioning → dark amber */
body.bright-mode .status-pending,
body.bright-mode .status-provisioning {
  background: rgba(180,83,9,.10); color: #92400e; border-color: rgba(180,83,9,.30);
}
/* Error → dark red */
body.bright-mode .status-error {
  background: rgba(185,28,28,.08); color: #991b1b; border-color: rgba(185,28,28,.25);
}
/* Role badges */
body.bright-mode .role-admin      { background: rgba(180,83,9,.12);  color: #92400e; }
body.bright-mode .role-developer  { background: rgba(109,40,217,.10); color: #5b21b6; }
/* Topbar user badge */
body.bright-mode .user-badge.admin { color: #92400e; border-color: rgba(180,83,9,.35); }
/* Key alert */
body.bright-mode .key-alert {
  background: rgba(180,83,9,.08); border-color: rgba(180,83,9,.25); color: #92400e;
}
/* Auth messages */
body.bright-mode .auth-error  { color: #991b1b; }
body.bright-mode .auth-success { color: #065f46; }
/* Toasts */
body.bright-mode .toast-item.ok  { color: #065f46; border-color: rgba(5,150,105,.40); }
body.bright-mode .toast-item.err { color: #991b1b; border-color: rgba(185,28,28,.35); }
/* Docs callouts */
body.bright-mode .docs-callout.warn {
  background: rgba(180,83,9,.08); border-color: #b45309; color: #92400e;
}
body.bright-mode .docs-callout.success {
  background: rgba(5,150,105,.08); border-color: #059669; color: #065f46;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: radial-gradient(ellipse 80% 60% at 50% 30%, #150830 0%, #04020a 65%);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  overflow-x: hidden;
}

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

/* ── Layout ─────────────────────────────────────────────────────── */
#app { min-height: 100vh; display: flex; flex-direction: column; }

.hidden { display: none !important; }

/* ── Auth screen ─────────────────────────────────────────────────── */
#auth-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100vh; padding: 24px;
}
.auth-logo {
  font-family: var(--font-mono); font-size: 2rem; font-weight: 700;
  color: var(--accent2); letter-spacing: 4px; margin-bottom: 8px;
  text-shadow: var(--glow-sm);
}
.auth-sub { color: var(--text2); font-size: .9rem; margin-bottom: 40px; }
.auth-card {
  background: rgba(14,10,26,0.92); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 36px; width: 100%; max-width: 420px;
  backdrop-filter: blur(12px);
}
.auth-tabs { display: flex; gap: 4px; margin-bottom: 28px; }
.auth-tab {
  flex: 1; padding: 8px; border: none; border-radius: var(--radius-sm);
  background: var(--surface2); color: var(--text2); font-family: var(--font);
  font-size: .9rem; cursor: pointer; transition: all .2s;
}
.auth-tab.active {
  background: var(--accent); color: #fff;
  box-shadow: var(--glow-sm);
}
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: .82rem; color: var(--text2); margin-bottom: 6px; }
.form-group input {
  width: 100%; padding: 11px 14px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: var(--font); font-size: .95rem;
  transition: border-color .2s;
  outline: none;
}
.form-group input:focus { border-color: var(--accent); box-shadow: var(--glow-sm); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border: none; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: all .2s; white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent-dim), var(--accent));
  color: #fff; box-shadow: var(--glow-sm);
}
.btn-primary:hover { box-shadow: var(--glow-md); transform: translateY(-1px); }
.btn-outline {
  background: transparent; color: var(--accent2);
  border: 1px solid var(--border-active);
}
.btn-outline:hover { background: var(--surface2); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-sm { padding: 6px 14px; font-size: .82rem; }
.btn-full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.auth-error {
  background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3);
  border-radius: var(--radius-sm); color: #fca5a5; font-size: .85rem;
  padding: 10px 14px; margin-bottom: 16px;
}
.auth-success {
  background: rgba(16,185,129,.12); border: 1px solid rgba(16,185,129,.3);
  border-radius: var(--radius-sm); color: #6ee7b7; font-size: .85rem;
  padding: 10px 14px; margin-bottom: 16px;
}
.btn-link {
  background: none; border: none; color: var(--accent2); font-size: .85rem;
  cursor: pointer; padding: 0; font-family: var(--font); text-decoration: underline;
  text-underline-offset: 3px;
}
.btn-link:hover { color: var(--text); }
.form-actions { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; }

/* ── Form select ─────────────────────────────────────────────────── */
.form-select {
  width: 100%; padding: 10px 14px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font); font-size: .9rem;
  outline: none; cursor: pointer; transition: border-color .2s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239d8cc5' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.form-select:focus { border-color: var(--accent); box-shadow: var(--glow-sm); }

/* ── Main app layout ──────────────────────────────────────────────── */
#main-app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 100;
  background: rgba(6,3,15,.97); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  display: flex; align-items: center; padding: 0 24px; height: 56px; gap: 24px;
}
.topbar-logo {
  font-family: var(--font-mono); font-weight: 700; color: var(--accent2);
  letter-spacing: 2px; font-size: 1rem; flex-shrink: 0;
}
.topbar-nav { display: flex; gap: 4px; flex: 1; }
.nav-item {
  padding: 6px 14px; border-radius: var(--radius-sm);
  color: var(--text2); font-size: .88rem; cursor: pointer;
  transition: all .2s; border: none; background: transparent;
  font-family: var(--font);
}
.nav-item:hover { color: var(--text); background: var(--surface2); }
.nav-item.active { color: var(--accent2); background: rgba(139,92,246,.12); }
.topbar-user {
  display: flex; align-items: center; gap: 10px;
  font-size: .85rem; color: var(--text2);
}
.user-badge {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px; font-size: .8rem;
  color: var(--accent2);
}
.user-badge.admin { color: #f59e0b; border-color: rgba(245,158,11,.3); }

.content { flex: 1; padding: 32px 24px; max-width: 1100px; margin: 0 auto; width: 100%; }

/* ── Views ──────────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ── Section / card ──────────────────────────────────────────────── */
.section-title {
  font-size: 1.3rem; font-weight: 700; color: var(--text);
  margin-bottom: 20px; display: flex; align-items: center; gap: 10px;
}
.section-title span { color: var(--text2); font-size: .85rem; font-weight: 400; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; margin-bottom: 20px;
}
.card-title {
  font-size: .95rem; font-weight: 600; color: var(--accent2);
  margin-bottom: 16px; display: flex; align-items: center; gap: 8px;
}

/* ── Instance card ──────────────────────────────────────────────── */
.instance-card {
  background: linear-gradient(135deg, var(--surface) 0%, rgba(22,16,40,.8) 100%);
  border: 1px solid var(--border-active);
  border-radius: var(--radius); padding: 28px;
}
.instance-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px; gap: 16px;
}
.instance-name {
  font-family: var(--font-mono); font-size: 1.1rem; color: var(--accent2);
  font-weight: 700;
}
.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px; font-size: .8rem; font-weight: 600;
}
.status-running { background: rgba(16,185,129,.12); color: #34d399; border: 1px solid rgba(16,185,129,.3); }
.status-stopped { background: rgba(156,163,175,.1); color: #9ca3af; border: 1px solid rgba(156,163,175,.2); }
.status-pending { background: rgba(245,158,11,.12); color: #fbbf24; border: 1px solid rgba(245,158,11,.3); }
.status-provisioning { background: rgba(245,158,11,.1); color: #fbbf24; border: 1px solid rgba(245,158,11,.3); }
.status-error { background: rgba(239,68,68,.1); color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }

.instance-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.inst-field label { font-size: .75rem; color: var(--text3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; display: block; }
.inst-field .val {
  font-family: var(--font-mono); font-size: .85rem; color: var(--text);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  word-break: break-all;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.copy-btn {
  background: none; border: none; color: var(--text3); cursor: pointer;
  padding: 2px 4px; border-radius: 4px; font-size: .75rem;
  transition: color .2s;
}
.copy-btn:hover { color: var(--accent2); }

.instance-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.no-instance {
  text-align: center; padding: 60px 24px;
}
.no-instance-icon { font-size: 3rem; margin-bottom: 16px; color: var(--text3); }
.no-instance h3 { font-size: 1.1rem; color: var(--text); margin-bottom: 8px; }
.no-instance p { color: var(--text2); font-size: .9rem; margin-bottom: 24px; }

/* ── Key download alert ──────────────────────────────────────────── */
.key-alert {
  background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.25);
  border-radius: var(--radius-sm); padding: 14px 18px; margin-bottom: 20px;
  font-size: .88rem; color: #fde68a;
  display: flex; align-items: center; gap: 12px;
}

/* ── Users table ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead tr { background: var(--surface3); }
th {
  padding: 10px 14px; text-align: left; font-size: .75rem;
  text-transform: uppercase; letter-spacing: .5px; color: var(--text2);
  font-weight: 600;
}
td { padding: 12px 14px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(139,92,246,.04); }

.role-badge {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  font-size: .75rem; font-weight: 600;
}
.role-admin { background: rgba(245,158,11,.15); color: #fbbf24; }
.role-developer { background: rgba(139,92,246,.12); color: var(--accent2); }
.td-actions { display: flex; gap: 6px; }

/* ── Skill store ─────────────────────────────────────────────────── */
.skill-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px; margin-top: 16px;
}
.skill-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; transition: border-color .2s;
}
.skill-card:hover { border-color: var(--border-active); }
.skill-card-name {
  font-family: var(--font-mono); color: var(--accent2);
  font-size: .9rem; font-weight: 700; margin-bottom: 4px;
}
.skill-card-desc { font-size: .83rem; color: var(--text2); margin-bottom: 12px; line-height: 1.5; }
.skill-card-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tag {
  background: var(--surface3); border: 1px solid var(--border);
  border-radius: 20px; padding: 2px 10px; font-size: .73rem; color: var(--text2);
}
.filter-chip {
  cursor: pointer; font-family: var(--font); transition: all .15s;
  background: var(--surface2); border-color: var(--border);
}
.filter-chip:hover { border-color: var(--accent); color: var(--accent2); }
.filter-chip.active { background: rgba(139,92,246,.18); border-color: var(--accent); color: var(--accent2); font-weight: 600; }

.sub-table td .status-badge { font-size: .75rem; padding: 2px 10px; }

.skills-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px; margin-top: 16px;
}
.skill-name {
  font-family: var(--font-mono); color: var(--accent2);
  font-size: .9rem; font-weight: 700; margin-bottom: 4px;
}
.skill-meta { font-size: .83rem; color: var(--text2); margin-bottom: 12px; line-height: 1.5; }
.skill-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.skill-badge {
  background: var(--surface3); border: 1px solid var(--border);
  border-radius: 20px; padding: 2px 10px; font-size: .73rem; color: var(--text2);
}
.skill-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }

/* ── Tabs ────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tab-btn {
  padding: 10px 18px; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text2); font-family: var(--font); font-size: .9rem; cursor: pointer;
  transition: all .2s; margin-bottom: -1px;
}
.tab-btn.active { color: var(--accent2); border-bottom-color: var(--accent); }
.tab-btn:hover:not(.active) { color: var(--text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Toast ───────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 18px;
  font-size: .88rem; color: var(--text); min-width: 240px;
  box-shadow: var(--glow-sm);
  animation: toastIn .25s ease;
}
.toast-item.ok { border-color: rgba(16,185,129,.4); color: #34d399; }
.toast-item.err { border-color: rgba(239,68,68,.4); color: #fca5a5; }
@keyframes toastIn { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:none; } }

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

/* ── Modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; width: 100%; max-width: 440px;
  box-shadow: var(--glow-md);
}
.modal-title { font-size: 1rem; font-weight: 700; margin-bottom: 20px; color: var(--text); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* ── Empty state ─────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text2); font-size: .9rem; }

/* ── Responsive — tablet (≤768px) ───────────────────────────────── */
@media (max-width: 768px) {
  .content { padding: 24px 18px; }
  .instance-fields { grid-template-columns: 1fr; gap: 12px; }
  .skill-grid,
  .skills-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

/* ── Responsive — mobile (≤640px) ───────────────────────────────── */
@media (max-width: 640px) {
  /* ── Base ──────────────────────────────────────────────── */
  .content { padding: 16px 12px; }

  /* ── Auth ──────────────────────────────────────────────── */
  .auth-card { padding: 24px 18px; }
  .auth-logo { font-size: 1.6rem; letter-spacing: 3px; }
  .auth-sub { margin-bottom: 28px; }

  /* ── Topbar — two-row layout ───────────────────────────── */
  .topbar {
    height: auto;
    flex-wrap: wrap;
    padding: 10px 14px 0;
    gap: 0;
  }
  .topbar-logo { flex: 1; font-size: .88rem; }
  .topbar-user { margin-left: auto; gap: 6px; }
  #user-name-display { display: none; }
  .user-badge { padding: 3px 9px; font-size: .74rem; }
  .topbar-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 6px 0 0;
    border-top: 1px solid var(--border);
    margin-top: 8px;
  }
  .topbar-nav::-webkit-scrollbar { display: none; }
  .nav-item { flex-shrink: 0; padding: 8px 12px; font-size: .82rem; }

  /* ── Section title ─────────────────────────────────────── */
  .section-title { font-size: 1.05rem; margin-bottom: 14px; }

  /* ── Instance card ─────────────────────────────────────── */
  .instance-card { padding: 16px 14px; }
  .instance-header { flex-direction: row; margin-bottom: 14px; align-items: center; }
  .instance-name { font-size: .9rem; }
  .instance-fields { grid-template-columns: 1fr; gap: 10px; margin-bottom: 16px; }
  .inst-field .val { font-size: .8rem; padding: 7px 10px; }

  /* ── Instance actions — 2-column grid ─────────────────── */
  .instance-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .instance-actions .btn {
    width: 100%;
    justify-content: center;
    font-size: .8rem;
    padding: 8px 10px;
  }
  /* Delete spans full width */
  .instance-actions .btn-danger {
    grid-column: 1 / -1;
    margin-left: 0 !important;
  }

  /* ── Tabs — horizontal scroll ──────────────────────────── */
  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-bottom: 16px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn { flex-shrink: 0; padding: 10px 14px; font-size: .82rem; }

  /* ── Skill / private-skills grid ───────────────────────── */
  .skill-grid,
  .skills-grid { grid-template-columns: 1fr; gap: 12px; }

  /* ── Admin table ───────────────────────────────────────── */
  th, td { padding: 8px 8px; font-size: .8rem; }
  .td-actions { flex-wrap: wrap; gap: 4px; }
  .td-actions .btn-sm { padding: 4px 7px; font-size: .72rem; }

  /* ── Modals — slide up from bottom ────────────────────── */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-height: 92vh;
    overflow-y: auto;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 22px 18px 32px;
    width: 100%;
    max-width: none;
  }
  .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
    margin-top: 20px;
  }
  .modal-actions .btn { width: 100%; justify-content: center; }
  /* Sub-edit: keep Delete separate, stack save/cancel */
  #sub-edit-modal .modal-actions { flex-direction: column; }
  #sub-edit-modal .modal-actions > div {
    display: flex; flex-direction: column-reverse; gap: 8px; width: 100%;
  }
  #sub-edit-modal .modal-actions > div .btn { width: 100%; }
  #sub-edit-modal .modal-actions .btn-danger { width: 100%; order: 3; }
  /* Manage key — attach row stacks vertically */
  .attach-row { flex-direction: column !important; }
  .attach-row select { width: 100%; }
  .attach-row .btn { width: 100%; justify-content: center; }

  /* ── Toast — full width ────────────────────────────────── */
  #toast { bottom: 16px; right: 12px; left: 12px; }
  .toast-item { min-width: 0; width: 100%; }

  /* ── Key alert ─────────────────────────────────────────── */
  .key-alert { flex-direction: column; gap: 6px; align-items: flex-start; }

  /* ── Form actions ──────────────────────────────────────── */
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }

  /* ── Card ──────────────────────────────────────────────── */
  .card { padding: 18px 14px; }

  /* ── Docs content ──────────────────────────────────────── */
  .docs-content { padding: 20px 14px; }

  /* ── FTP modal — stacked layout on mobile ──────────────── */
  .ftp-body { flex-direction: column !important; }
  .ftp-sidebar {
    width: 100% !important;
    height: 220px;
    border-right: none !important;
    border-bottom: 1px solid var(--border) !important;
    flex-shrink: 0 !important;
  }
  .ftp-editor-area { min-width: 0; }
}

/* ── Responsive — extra-small (≤420px) ──────────────────────────── */
@media (max-width: 420px) {
  .instance-actions { grid-template-columns: 1fr; }
  .topbar-logo { font-size: .8rem; letter-spacing: 1.5px; }
  .auth-logo { font-size: 1.4rem; }
}

/* ── Documentation page ───────────────────────────────────────── */
#view-docs { padding: 0; }

.docs-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 0;
  min-height: calc(100vh - 56px);
  align-items: start;
}

.docs-sidebar {
  border-right: 1px solid var(--border);
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  overflow-x: hidden;
}

.docs-sidebar-inner {
  padding: 24px 16px;
}

.docs-sidebar-title {
  font-size: .75rem; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text3); margin-bottom: 12px;
}

.docs-toc { display: flex; flex-direction: column; gap: 1px; }

.docs-toc-link {
  display: block; padding: 6px 10px; border-radius: var(--radius-sm);
  color: var(--text2); font-size: .83rem; text-decoration: none;
  transition: all .15s; cursor: pointer; background: none; border: none;
  text-align: left; width: 100%; font-family: var(--font);
}
.docs-toc-link:hover { color: var(--text); background: var(--surface2); }
.docs-toc-link.active { color: var(--accent2); background: rgba(139,92,246,.1); }

.docs-content {
  padding: 32px 40px;
  min-width: 0;
}

/* Section headers */
.docs-section { margin-bottom: 60px; scroll-margin-top: 80px; }
.docs-section h2 {
  font-size: 1.5rem; font-weight: 700; color: var(--text);
  border-bottom: 2px solid var(--border); padding-bottom: 12px; margin-bottom: 20px;
}
.docs-section h3 {
  font-size: 1.05rem; font-weight: 600; color: var(--accent2);
  margin: 28px 0 12px;
}
.docs-section h4 {
  font-size: .9rem; font-weight: 600; color: var(--text);
  margin: 20px 0 8px;
}
.docs-section p { color: var(--text2); line-height: 1.75; margin-bottom: 12px; }
.docs-section ul, .docs-section ol {
  color: var(--text2); padding-left: 20px; margin-bottom: 12px; line-height: 1.75;
}
.docs-section li { margin-bottom: 4px; }
.docs-section strong { color: var(--text); font-weight: 600; }
.docs-section code {
  background: var(--surface3); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px; font-family: var(--font-mono);
  font-size: .82em; color: var(--accent2);
}

/* Code blocks */
.docs-pre {
  background: rgba(10,6,20,0.9); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin: 16px 0;
  overflow-x: auto; position: relative;
}
.docs-pre code {
  background: none; border: none; padding: 0;
  font-family: var(--font-mono); font-size: .8rem;
  color: #c9d1d9; line-height: 1.7; white-space: pre;
  display: block;
}

/* Callout boxes */
.docs-callout {
  border-left: 3px solid var(--accent); background: rgba(139,92,246,.08);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 14px 18px; margin: 16px 0; color: var(--text2); font-size: .9rem;
}
.docs-callout.warn {
  border-color: #f59e0b; background: rgba(245,158,11,.08); color: #fde68a;
}
.docs-callout.success {
  border-color: #10b981; background: rgba(16,185,129,.08); color: #6ee7b7;
}

/* Docs table */
.docs-table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: .85rem; }
.docs-table th {
  text-align: left; padding: 8px 14px; background: var(--surface2);
  color: var(--text3); font-size: .75rem; font-weight: 600; letter-spacing: .5px;
  text-transform: uppercase; border-bottom: 1px solid var(--border);
}
.docs-table td {
  padding: 10px 14px; border-bottom: 1px solid rgba(139,92,246,.08);
  color: var(--text2); vertical-align: top;
}
.docs-table td code { font-size: .78rem; }
.docs-table tr:last-child td { border-bottom: none; }
.docs-table tr:hover td { background: rgba(139,92,246,.04); }

/* Five Pillars box */
.docs-pillars {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; margin: 16px 0;
}
.docs-pillar {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; gap: 14px; align-items: flex-start;
}
.docs-pillar:last-child { border-bottom: none; }
.docs-pillar-num {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(139,92,246,.2); border: 1px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; color: var(--accent2); margin-top: 1px;
}
.docs-pillar-body strong { color: var(--text); font-size: .9rem; display: block; margin-bottom: 4px; }
.docs-pillar-body p { color: var(--text2); font-size: .85rem; margin: 0; }

@media (max-width: 900px) {
  .docs-layout { grid-template-columns: 1fr; }
  .docs-sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .docs-content { padding: 24px 20px; }
}

/* ── Theme tab ────────────────────────────────────────────────── */
.theme-section { margin-bottom: 24px; }
.theme-section-title { font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text2); margin-bottom: 14px; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.theme-field label { display: block; font-size: .8rem; color: var(--text2); margin-bottom: 6px; }
.theme-field .field-hint { font-size: .72rem; color: var(--text3); margin-top: 4px; }

.color-row { display: flex; align-items: center; gap: 8px; }
.color-picker {
  width: 38px; height: 34px; padding: 2px; border: 1px solid var(--border);
  border-radius: 6px; background: transparent; cursor: pointer; flex-shrink: 0;
}
.color-hex {
  flex: 1; font-family: var(--font-mono); font-size: .82rem;
  padding: 7px 10px; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); outline: none;
}
.color-hex:focus { border-color: var(--accent); }

.mode-btn {
  padding: 8px 20px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface2); color: var(--text2); font-family: var(--font);
  font-size: .85rem; cursor: pointer; transition: all .2s;
}
.mode-btn.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
  box-shadow: var(--glow-sm);
}

.brand-upload-area {
  min-height: 52px; border: 1px dashed var(--border); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px; overflow: hidden; background: var(--surface2);
}
.brand-upload-area img { max-height: 52px; max-width: 100%; object-fit: contain; padding: 6px; }
.brand-upload-dark { background: var(--surface); }
.brand-upload-bright { background: #f5f3ff; }
.brand-upload-favicon { background: var(--surface2); min-height: 44px; }

.theme-font-preview {
  font-size: 18px; color: var(--text); min-height: 30px; margin-top: 8px;
  padding: 8px 12px; background: var(--surface2); border-radius: 8px;
  border: 1px solid var(--border);
}
