/* ── Reset & Variables ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0f1a;
  --bg2:       #12151f;
  --card:      #1a1e2e;
  --card2:     #1e2235;
  --border:    #2a2f47;
  --accent:    #6366f1;
  --accent-h:  #4f52d8;
  --accent-d:  rgba(99,102,241,0.15);
  --success:   #22c55e;
  --warning:   #f59e0b;
  --danger:    #ef4444;
  --text:      #e2e8f0;
  --text2:     #94a3b8;
  --text3:     #4f5882;
  --radius:    10px;
  --sidebar-w: 240px;
}

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

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

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Form elements ─────────────────────────────────────────────────────────── */
input, select, textarea {
  width: 100%;
  padding: .6rem .9rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .95rem;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-d);
}
input::placeholder { color: var(--text3); }
select option { background: var(--card); }
label { display: block; margin-bottom: .35rem; font-size: .85rem; color: var(--text2); font-weight: 500; }
.field { margin-bottom: 1.1rem; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s, background .15s;
  white-space: nowrap;
}
.btn:hover   { opacity: .88; }
.btn:active  { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); opacity: 1; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-ghost   { background: transparent; border: 1px solid var(--border); color: var(--text2); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); opacity: 1; }
.btn-sm { padding: .35rem .8rem; font-size: .82rem; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-full { width: 100%; justify-content: center; }

/* ── Auth pages ────────────────────────────────────────────────────────────── */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 30% 20%, rgba(99,102,241,.12) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 80%, rgba(99,102,241,.08) 0%, transparent 60%),
              var(--bg);
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem;
  box-shadow: 0 25px 50px rgba(0,0,0,.5);
}

.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.auth-logo .icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: .5rem;
}
.auth-logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.auth-logo p {
  color: var(--text2);
  font-size: .9rem;
  margin-top: .2rem;
}

.auth-error {
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  color: #fca5a5;
  padding: .7rem 1rem;
  border-radius: var(--radius);
  font-size: .88rem;
  margin-bottom: 1.2rem;
  display: none;
}
.auth-error.show { display: block; }

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: .85rem;
  color: var(--text2);
}

/* OTP input */
.otp-input {
  letter-spacing: .5rem;
  font-size: 1.4rem;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* QR code display */
.qr-wrap {
  text-align: center;
  margin: 1.5rem 0;
}
.qr-wrap img {
  border-radius: var(--radius);
  max-width: 200px;
  background: #fff;
  padding: 8px;
}
.secret-key {
  font-family: monospace;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem 1rem;
  font-size: .85rem;
  word-break: break-all;
  text-align: center;
  color: var(--text2);
  margin-top: .8rem;
}

/* ── Dashboard layout ──────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
  transition: transform .2s;
}
.sidebar-logo {
  padding: 1.2rem 1.4rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .7rem;
}
.sidebar-logo .icon { font-size: 1.5rem; }
.sidebar-logo span { font-size: 1.1rem; font-weight: 700; letter-spacing: -.02em; }

.sidebar-nav { flex: 1; padding: .8rem 0; overflow-y: auto; }
.nav-group { margin-bottom: 1.2rem; }
.nav-label {
  padding: .3rem 1.4rem;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text3);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .55rem 1.4rem;
  color: var(--text2);
  font-size: .9rem;
  cursor: pointer;
  border-radius: 0;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(99,102,241,.08); color: var(--text); }
.nav-item.active { background: var(--accent-d); color: var(--accent); border-left-color: var(--accent); }
.nav-item .icon { width: 20px; text-align: center; }

.sidebar-footer {
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .6rem;
}
.avatar {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: .9rem;
  flex-shrink: 0;
}
.sidebar-footer .user-info { flex: 1; overflow: hidden; }
.sidebar-footer .user-info .name { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .user-info .role { font-size: .75rem; color: var(--text2); }

/* Main content */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  padding: 1rem 1.8rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg2);
  position: sticky; top: 0; z-index: 40;
}
.topbar h2 { font-size: 1.15rem; font-weight: 700; }

.content {
  padding: 1.8rem;
  flex: 1;
}

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

/* ── Cards / Grid ──────────────────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.2rem;
}

.server-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.4rem;
  transition: border-color .2s, box-shadow .2s;
  cursor: pointer;
}
.server-card:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-d); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.card-title { font-weight: 700; font-size: 1rem; }
.card-subtitle { font-size: .82rem; color: var(--text2); margin-top: .1rem; }

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .8rem;
  font-weight: 600;
  padding: .2rem .6rem;
  border-radius: 20px;
}
.status-dot::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.status-started  { color: var(--success); background: rgba(34,197,94,.12); }
.status-stopped  { color: var(--danger);  background: rgba(239,68,68,.12); }
.status-unknown,
.status-unreachable { color: var(--text3); background: rgba(255,255,255,.05); }
.status-loading  { color: var(--text2);   background: rgba(255,255,255,.05); }

.card-meta {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: .82rem;
  color: var(--text2);
}

.card-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

/* ── Detail panel ──────────────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
}
.stat-card .label { font-size: .78rem; color: var(--text2); margin-bottom: .3rem; }
.stat-card .value { font-size: 1.2rem; font-weight: 700; }

.log-box {
  background: #080a10;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: 'Consolas', 'Fira Code', monospace;
  font-size: .8rem;
  line-height: 1.6;
  color: #b0c4de;
  max-height: 450px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 60px rgba(0,0,0,.6);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--text2); cursor: pointer;
  font-size: 1.3rem; line-height: 1; padding: 2px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .6rem;
}

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: .8rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .06em; }
tr:hover td { background: rgba(255,255,255,.02); }

/* ── Toast notifications ───────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.toast {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1.1rem;
  font-size: .88rem;
  min-width: 260px;
  max-width: 380px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  gap: .6rem;
  animation: slideIn .2s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger);  }
.toast.info    { border-left: 3px solid var(--accent);  }
@keyframes slideIn { from { opacity:0; transform: translateX(20px); } }

/* ── Misc ──────────────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
}
.section-header h3 { font-size: 1.05rem; font-weight: 700; }

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text2);
}
.empty-state .icon { font-size: 3rem; display: block; margin-bottom: 1rem; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .55rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-admin   { background: rgba(99,102,241,.2); color: #a5b4fc; }
.badge-user    { background: rgba(255,255,255,.07); color: var(--text2); }
.badge-enabled { background: rgba(34,197,94,.15); color: #86efac; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  color: var(--text2);
  cursor: pointer;
  font-size: .88rem;
  margin-bottom: 1.2rem;
  border: none;
  background: none;
  padding: 0;
}
.back-btn:hover { color: var(--text); }

/* ── Terminal / log output ─────────────────────────────────────────────────── */
.terminal-box {
  background: #060810;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: 'Consolas', 'Fira Code', 'Cascadia Code', monospace;
  font-size: .8rem;
  line-height: 1.55;
  color: #c8d8f0;
  max-height: 500px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.terminal-box.full { max-height: none; }

/* ── Activity log ──────────────────────────────────────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: .75rem;
  font-weight: 600;
  padding: .15rem .5rem;
  border-radius: 20px;
}
.pill-success { background: rgba(34,197,94,.15);  color: #86efac; }
.pill-error   { background: rgba(239,68,68,.15);  color: #fca5a5; }
.pill-warning { background: rgba(245,158,11,.15); color: #fcd34d; }

/* ── Scan results ──────────────────────────────────────────────────────────── */
.scan-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.scan-card + .scan-card { margin-top: .6rem; }
.scan-info .script { font-family: monospace; font-size: .88rem; color: var(--accent); }
.scan-info .meta   { font-size: .78rem; color: var(--text2); margin-top: .2rem; }

/* ── Deploy progress ───────────────────────────────────────────────────────── */
.deploy-step {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .8rem;
  border-radius: var(--radius);
  font-size: .85rem;
  background: var(--bg2);
  border: 1px solid var(--border);
}
.deploy-step + .deploy-step { margin-top: .4rem; }
.deploy-step.done    { border-color: rgba(34,197,94,.3); }
.deploy-step.running { border-color: var(--accent); animation: pulse 1.5s infinite; }
.deploy-step.error   { border-color: rgba(239,68,68,.3); }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.6; } }

/* ── Code inline ───────────────────────────────────────────────────────────── */
code {
  font-family: monospace;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .1rem .4rem;
  font-size: .85em;
  color: var(--accent);
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-240px); }
  .sidebar.open { transform: translateX(0); --sidebar-w: 240px; }
  .main { margin-left: 0; }
  .detail-grid { grid-template-columns: 1fr; }
}
