:root {
  --bg: #0c1017;
  --bg-elev: #131924;
  --bg-card: #161e2b;
  --bg-input: #0e141e;
  --border: #253145;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  height: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #182338 0%, var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.brand-row h1 { margin: 0; font-size: 20px; }
.brand-row p { margin: 2px 0 0; font-size: 12px; }
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

form label {
  display: block;
  margin-bottom: 14px;
}
form label span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}
input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  background: var(--bg-elev);
  transition: background 0.15s, border-color 0.15s;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
}
.btn-ghost:hover { background: rgba(255,255,255,0.06); }
.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.28); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; }

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11px; color: var(--muted); }

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 14px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.active { background: rgba(59, 130, 246, 0.16); color: #93c5fd; font-weight: 600; }
.nav-icon { font-family: var(--mono); width: 20px; text-align: center; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.user-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
}
.user-name { font-weight: 600; font-size: 13px; }
.footer-actions { display: flex; gap: 6px; }
.footer-actions .btn { flex: 1; }

.main-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 18px 24px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar h2 { margin: 0; font-size: 19px; }

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

/* Cards & Stats */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-header h3 { margin: 0; font-size: 15px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 20px; font-weight: 700; font-family: var(--mono); }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sparkline { width: 100%; height: 36px; margin-top: 8px; display: block; }

.progress-bar {
  height: 7px;
  background: var(--bg-input);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 10px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s;
}

/* Badges & Pills */
.badge, .status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge { background: rgba(59,130,246,0.18); color: #93c5fd; }
.badge-admin { background: rgba(239,68,68,0.18); color: #fca5a5; }
.badge-moderator { background: rgba(245,158,11,0.18); color: #fcd34d; }
.badge-viewer { background: rgba(148,163,184,0.2); color: #cbd5e1; }
.status-ok { background: rgba(34,197,94,0.16); color: #86efac; }
.status-warn { background: rgba(245,158,11,0.16); color: #fde68a; }
.status-err { background: rgba(239,68,68,0.16); color: #fca5a5; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid rgba(37, 49, 69, 0.7);
}
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr:hover td { background: rgba(255,255,255,0.02); }
.mono { font-family: var(--mono); }

/* Console */
.console-card {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 105px);
  min-height: 480px;
}
.console-toolbar, .files-toolbar, .logs-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.logs-toolbar { justify-content: flex-start; }
.logs-toolbar select, .logs-toolbar input { width: auto; min-width: 150px; }
.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-label { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--muted); }
.inline-label select { width: auto; }
.inline-label input[type="checkbox"] { width: auto; }

.terminal {
  flex: 1;
  background: #080b10;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.48;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #d6e0f0;
}
.log-viewer { height: calc(100vh - 205px); min-height: 400px; margin: 0; }
.log-line-err { color: #f87171; }
.log-line-warn { color: #fbbf24; }
.log-line-sys { color: #60a5fa; }
.log-line-cmd { color: #34d399; font-weight: 600; }

.console-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.prompt-chevron { font-family: var(--mono); color: var(--accent); font-weight: 700; }
.mod-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}

/* Files */
.files-layout {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 14px;
}
.files-shortcuts h4 { margin: 0 0 10px; font-size: 12px; color: var(--muted); text-transform: uppercase; }
.shortcut-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
}
.shortcut-btn:hover { background: rgba(59,130,246,0.14); color: #93c5fd; }

.breadcrumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-family: var(--mono); font-size: 12px; }
.crumb-btn {
  background: none;
  border: none;
  color: #93c5fd;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}
.crumb-btn:hover { background: rgba(59,130,246,0.15); }
.file-link {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  font-size: 13px;
  text-align: left;
}
.file-link:hover { color: #93c5fd; text-decoration: underline; }
.file-link.is-dir { color: #93c5fd; font-weight: 600; }
.upload-label { cursor: pointer; margin: 0; }
#files-dropzone.drag-over { outline: 2px dashed var(--accent); outline-offset: -4px; }

/* Admin */
.admin-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 16px;
}
.inline-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
}
.code-textarea {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
}

/* Alerts, Modals, Toast */
.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  margin-bottom: 12px;
}
.alert-error { background: rgba(239,68,68,0.14); border: 1px solid rgba(239,68,68,0.4); color: #fca5a5; }
.alert-warn { background: rgba(245,158,11,0.14); border: 1px solid rgba(245,158,11,0.4); color: #fde68a; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.modal-sm { max-width: 400px; }
.modal-lg { max-width: 980px; height: 84vh; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.editor-full { flex: 1; height: 100%; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #1e293b;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45);
  z-index: 100;
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .files-layout, .admin-grid { grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: 1fr; }
}
