:root {
  --bg: #070a10;
  --bg-elevated: #0c111b;
  --bg-card: #101725;
  --bg-input: #080c14;
  --border: #1a2538;
  --border-strong: #263754;
  --text: #e6edf7;
  --text-muted: #7f91ad;
  --accent: #00a8ff;
  --accent-bright: #38bdf8;
  --accent-dim: rgba(0, 168, 255, 0.14);
  --accent-glow: 0 0 22px rgba(0, 168, 255, 0.28);
  --green: #10b981;
  --green-dim: rgba(16, 185, 129, 0.14);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.14);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.15);
  --radius: 10px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

.hidden { display: none !important; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--text-muted); }

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--accent-bright);
  background: rgba(0, 168, 255, 0.09);
  padding: 1px 6px;
  border-radius: 5px;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 35% at 50% -10%, rgba(0, 168, 255, 0.16), transparent 70%),
    radial-gradient(35% 30% at 95% 15%, rgba(56, 189, 248, 0.08), transparent 70%);
  z-index: 0;
}

.nl-card {
  position: relative;
  background: linear-gradient(180deg, rgba(16, 23, 37, 0.96), rgba(11, 16, 27, 0.98));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.nl-accent-line {
  position: absolute;
  top: 0;
  left: 14px;
  right: 14px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: var(--accent-glow);
}

/* BRAND */
.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 16px;
}
.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  transform: rotate(45deg);
}
.brand-mark .accent, .mobile-brand .accent { color: var(--accent); }
.brand-tag {
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* LOGIN */
.login-shell {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 26px 24px;
}
.login-header {
  text-align: center;
  margin-bottom: 24px;
}
.login-sub {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* FORMS & BUTTONS */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field.full { grid-column: 1 / -1; }
.field label {
  font-size: 12px;
  font-weight: 600;
  color: #a9bad4;
  letter-spacing: 0.02em;
}
.field-hint {
  font-size: 12px;
  min-height: 16px;
  color: var(--text-muted);
}
.field-hint.ok { color: var(--green); }
.field-hint.err { color: var(--red); }

input, select, textarea {
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 168, 255, 0.15);
}

.input-group {
  display: flex;
  align-items: stretch;
  gap: 6px;
}
.input-group input { flex: 1; min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-full { width: 100%; padding: 12px; font-size: 14px; }
.btn-sm { padding: 8px 13px; font-size: 13px; }
.btn-xs { padding: 0 11px; font-size: 12px; }

.btn-primary {
  background: linear-gradient(135deg, #0095e8, #0074cc);
  color: #fff;
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: 0 0 18px rgba(0, 168, 255, 0.22);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #00a8ff, #0284c7);
  box-shadow: 0 0 24px rgba(0, 168, 255, 0.38);
}
.btn-secondary {
  background: #131c2e;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-bright);
}
.btn-danger {
  background: var(--red-dim);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
  color: #fff;
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-strong);
}
.icon-btn {
  background: #11192a;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 40px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.icon-btn:hover { color: var(--accent-bright); border-color: var(--accent); }

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.alert-error {
  background: var(--red-dim);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
}

/* APP LAYOUT */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: rgba(10, 14, 23, 0.94);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100dvh;
}
.sidebar-brand {
  padding: 4px 10px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}
.nav-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}
.nav-item.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(0, 168, 255, 0.18), rgba(0, 168, 255, 0.03));
  border-color: rgba(0, 168, 255, 0.35);
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav-icon {
  color: var(--accent);
  width: 18px;
  text-align: center;
  font-family: var(--font-mono);
}

.sidebar-footer {
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(8, 12, 20, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.mobile-brand {
  display: none;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  letter-spacing: 0.07em;
}
.mobile-only { display: none; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.status-dot.online { background: var(--green); box-shadow: 0 0 10px var(--green); }
.status-dot.error { background: var(--red); box-shadow: 0 0 10px var(--red); }
.status-dot.restarting { background: var(--amber); box-shadow: 0 0 10px var(--amber); }

.dirty-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--amber);
  background: var(--amber-dim);
  border: 1px solid rgba(245, 158, 11, 0.35);
  padding: 4px 10px;
  border-radius: 999px;
}

/* STATUS STRIP */
.status-strip {
  display: flex;
  gap: 10px;
  padding: 14px 22px 0;
  overflow-x: auto;
}
.mini-bot-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  white-space: nowrap;
}
.mini-bot-chip strong { color: var(--text); }
.mini-bot-chip .handle { color: var(--accent-bright); font-family: var(--font-mono); }
.mini-bot-chip .err-msg { color: #fca5a5; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

/* CONTENT */
.content-scroll {
  padding: 18px 22px 40px;
  max-width: 1120px;
  width: 100%;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.section-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}
.section-head p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.form-card { padding: 18px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.cards-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.bot-card {
  padding: 16px 18px 18px;
}
.bot-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.bot-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.bot-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--accent-dim);
  color: var(--accent-bright);
  border: 1px solid rgba(0, 168, 255, 0.3);
}
.bot-live-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.db-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.json-editor {
  min-height: 440px;
  resize: vertical;
  line-height: 1.5;
  font-size: 13px;
  margin-bottom: 10px;
}

.two-col {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 16px;
}
.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-title-row h3, .form-card h3 {
  margin: 0;
  font-size: 15px;
}
.stack-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.logs-box {
  background: #05080d;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  height: 360px;
  overflow-y: auto;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.log-line { word-break: break-word; }
.log-time { color: var(--text-muted); margin-right: 6px; }
.log-ERROR { color: #fca5a5; }
.log-WARNING { color: #fcd34d; }
.log-INFO { color: #cbd5e1; }

.backups-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}
.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.backup-meta { min-width: 0; }
.backup-name {
  font-family: var(--font-mono);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.backup-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* BANNERS */
.upload-zone {
  padding: 18px;
  margin-bottom: 16px;
  border-style: dashed;
  border-color: var(--border-strong);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(0, 168, 255, 0.08);
}
.upload-zone-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.upload-icon {
  font-size: 26px;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  border: 1px solid rgba(0, 168, 255, 0.3);
  border-radius: 10px;
}
.upload-title { font-weight: 600; font-size: 14px; }
.upload-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.banners-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.banner-card {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.banner-thumb-wrap {
  position: relative;
  background: #05080d;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.banner-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.banner-slot-pill {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(7, 10, 16, 0.85);
  border: 1px solid rgba(0, 168, 255, 0.45);
  color: var(--accent-bright);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
}
.banner-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.banner-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.banner-name { font-family: var(--font-mono); font-size: 13px; font-weight: 600; }
.banner-size { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }
.banner-warn { font-size: 11px; color: var(--amber); }
.banner-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* MOBILE BOTTOM NAV */
.mobile-nav { display: none; }

/* TOASTS */
.toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  background: #0e1626;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }

/* RESPONSIVE / MOBILE */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .mobile-brand { display: inline-flex; }
  .mobile-only { display: inline-flex; }

  .topbar {
    padding: 10px 14px;
  }
  .topbar-actions {
    width: 100%;
  }
  .topbar-actions #btn-only-restart { flex: 0 0 auto; }
  .topbar-actions #btn-save-restart { flex: 1; }

  .status-strip { padding: 10px 14px 0; }
  .content-scroll {
    padding: 14px 14px 92px;
  }
  .form-grid, .two-col, .db-row {
    grid-template-columns: 1fr;
  }

  /* Prevent iOS zoom on input tap */
  input, select, textarea {
    font-size: 16px;
    min-height: 44px;
  }
  .btn-sm, .btn-xs { min-height: 40px; }
  .icon-btn { min-width: 44px; min-height: 44px; }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    background: rgba(8, 12, 20, 0.96);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    padding: 6px 2px calc(6px + env(safe-area-inset-bottom));
  }
  .m-nav-item {
    background: transparent;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 2px;
    font-size: 11px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
  }
  .m-ico {
    font-size: 15px;
    font-family: var(--font-mono);
  }
  .m-nav-item.active {
    color: var(--accent-bright);
  }

  .toast-container {
    left: 14px;
    right: 14px;
    bottom: 74px;
    max-width: none;
  }
}

