/* ============================================================
   SooperDB v1.0 - panel styles
   Sidebar is FULLY STICKY: fixed to the viewport, its own scroll,
   never moves when the main content scrolls.
   ============================================================ */
:root {
  --sidebar-w: 260px;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1e293b;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #16a34a;
  --ok-soft: #f0fdf4;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 12px rgba(15, 23, 42, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  word-break: break-all;
}
.icon { width: 20px; height: 20px; flex: none; }
.muted { color: var(--muted); }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Sticky sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;              /* sidebar scrolls on its own */
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

.logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px;
  color: #fff; font-size: 21px; font-weight: 800; letter-spacing: -.5px;
}
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: inline-flex; align-items: center; justify-content: center; color: #fff;
}
.logo-mark .icon { width: 20px; height: 20px; }

.nav { padding: 8px 12px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 3px;
  border-radius: 9px;
  color: var(--sidebar-text);
  font-size: 14.5px; font-weight: 500;
  background: none; border: none; cursor: pointer;
  text-align: left;
}
.nav-item:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .nav-caret { margin-left: auto; transition: transform .2s; }
.nav-item .nav-caret .icon { width: 16px; height: 16px; }
.nav-group.open .nav-caret { transform: rotate(180deg); }
.nav-sub { display: none; padding: 2px 0 6px 12px; }
.nav-group.open .nav-sub { display: block; }
.nav-sub-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; margin-bottom: 2px;
  border-radius: 8px; color: var(--sidebar-text);
  font-size: 14px; font-weight: 500;
  border-left: 2px solid #1e293b;
}
.nav-sub-item:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav-sub-item.active { background: var(--sidebar-active); color: #fff; border-left-color: var(--primary); }
.nav-sub-item .icon { width: 17px; height: 17px; }

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid #1e293b;
  margin-top: auto;
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.sidebar-user-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sidebar-user-meta strong { color: #fff; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-meta small { color: #94a3b8; font-size: 12px; }
.sidebar-logout { color: #94a3b8; display: inline-flex; }
.sidebar-logout:hover { color: #fff; }

/* ---------- Main column ---------- */
.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex; align-items: center; gap: 14px;
}
.topbar-titles h1 { margin: 0; font-size: 21px; letter-spacing: -.4px; }
.topbar-titles p { margin: 1px 0 0; color: var(--muted); font-size: 13.5px; }
.content { padding: 24px 28px 48px; flex: 1; }
.hamburger { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; width: 38px; height: 38px; cursor: pointer; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.hamburger span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px; }

/* ---------- Cards, grids, stats ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 20px; }
.card h2 { margin: 0 0 6px; font-size: 17px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; display: flex; align-items: center; gap: 8px; }
.card-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.narrow-card { max-width: 640px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-grid-2 { grid-template-columns: repeat(2, 1fr); }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; display: flex; gap: 14px; align-items: center; }
.stat-card strong { display: block; font-size: 26px; line-height: 1.1; letter-spacing: -.5px; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-icon { width: 44px; height: 44px; border-radius: 11px; background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.stat-card-cta { padding: 0; }
.stat-card-cta a { display: flex; align-items: center; gap: 10px; width: 100%; height: 100%; padding: 18px; color: var(--primary); font-weight: 600; }
.stat-card-cta a:hover { text-decoration: none; background: var(--primary-soft); border-radius: var(--radius); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }
.table-scroll { overflow-x: auto; }

/* ---------- Badges, buttons ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f1f5f9; color: #475569; white-space: nowrap; }
.badge-admin { background: #ede9fe; color: #6d28d9; }
.badge-user { background: #e0f2fe; color: #0369a1; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-err { background: var(--danger-soft); color: var(--danger); }
.badge-method { background: #f1f5f9; color: #334155; font-family: ui-monospace, monospace; font-size: 11.5px; }

.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; border-radius: 9px; border: 1px solid var(--border); background: #fff; color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; background: #f8fafc; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 15.5px; }
.btn-block { width: 100%; justify-content: center; }
.icon-btn { background: none; border: none; cursor: pointer; color: var(--muted); padding: 6px; border-radius: 8px; display: inline-flex; }
.icon-btn:hover { background: #f1f5f9; color: var(--text); }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; position: relative; padding-right: 40px; }
.alert-success { background: var(--ok-soft); color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: var(--danger-soft); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warn-soft); color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: var(--primary-soft); color: #3730a3; border: 1px solid #c7d2fe; }
.alert-close { position: absolute; right: 10px; top: 8px; background: none; border: none; font-size: 20px; cursor: pointer; color: inherit; opacity: .6; }
.alert-close:hover { opacity: 1; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 15px; }
.field > span { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 5px; }
.field input[type=text], .field input[type=email], .field input[type=password], .field select, .field textarea,
.toolbar input[type=text], .toolbar select, .search-form input[type=text] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 14.5px; font-family: inherit; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus, .toolbar input:focus, .toolbar select:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }
.field input:disabled { background: #f8fafc; color: var(--muted); }
.field .hint, .hint { display: block; color: var(--muted); font-size: 12.5px; margin-top: 4px; font-weight: 400; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 15px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.code-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13.5px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; font-family: ui-monospace, monospace; font-size: 13px; }

/* ---------- Toolbar / search ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-right { justify-content: flex-end; }
.search-form { display: flex; gap: 8px; align-items: center; flex: 1; min-width: 240px; position: relative; }
.search-form input[type=text] { padding-left: 36px; }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); display: inline-flex; }
.search-icon .icon { width: 17px; height: 17px; }

/* ---------- Dropdown (3-dot menus) ---------- */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px);
  min-width: 190px; background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .15); z-index: 60; padding: 6px;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border: none; background: none; cursor: pointer;
  font-size: 14px; color: var(--text); border-radius: 7px; text-align: left; font-family: inherit;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: #f1f5f9; text-decoration: none; }
.dropdown-menu .danger { color: var(--danger); }
.dropdown-menu .danger:hover { background: var(--danger-soft); }
.dropdown-form { margin: 0; }
.dropdown-menu .icon { width: 16px; height: 16px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .55); }
.modal-card { position: relative; background: #fff; border-radius: 14px; box-shadow: 0 20px 60px rgba(15, 23, 42, .3); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: 22px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.json-view { background: #0f172a; color: #e2e8f0; border-radius: 10px; padding: 16px; overflow: auto; max-height: 55vh; font-size: 13px; margin: 0; }
.json-view code { background: none; border: none; color: inherit; padding: 0; }

/* ---------- Code blocks / lang tabs ---------- */
.code-block { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 14px; }
.code-head { display: flex; justify-content: space-between; align-items: center; background: #f8fafc; border-bottom: 1px solid var(--border); padding: 8px 12px; font-size: 13px; font-weight: 600; }
.code-block pre { margin: 0; padding: 14px; overflow-x: auto; background: #0f172a; color: #e2e8f0; font-size: 13px; line-height: 1.6; }
.code-block pre code { background: none; border: none; color: inherit; padding: 0; font-size: 13px; }
.lang-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0; }
.lang-tab { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: #fff; font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--muted); }
.lang-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.lang-panel { display: none; }
.lang-panel.active { display: block; }

/* ---------- DB open page ---------- */
.db-subheader { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.db-stats { display: flex; gap: 16px; color: var(--muted); font-size: 13.5px; }
.db-stats strong { color: var(--text); }
.tab-select-wrap { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.tab-select { padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; font-weight: 600; background: #fff; cursor: pointer; }
.db-layout { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.db-subnav { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; position: sticky; top: 88px; max-height: calc(100vh - 110px); overflow-y: auto; }
.db-subnav h3 { margin: 0 0 12px; font-size: 15px; }
.collection-list { list-style: none; margin: 0 0 14px; padding: 0; }
.collection-list li { border-radius: 8px; margin-bottom: 2px; }
.collection-list li a { display: flex; align-items: center; gap: 9px; padding: 9px 10px; color: var(--text); font-size: 14px; font-weight: 500; }
.collection-list li a:hover { text-decoration: none; background: #f8fafc; }
.collection-list li.active { background: var(--primary-soft); }
.collection-list li.active a { color: var(--primary-dark); }
.collection-list li em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--muted); background: #f1f5f9; padding: 1px 8px; border-radius: 999px; }
.collection-list .icon { width: 17px; height: 17px; color: var(--muted); }
.collection-add input { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; margin-bottom: 8px; }
.subnav-note { margin-top: 16px; padding: 12px; background: #f8fafc; border: 1px solid var(--border); border-radius: 9px; font-size: 13px; color: var(--muted); }
.subnav-links { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.subnav-links .btn { justify-content: center; }
.detail-list { margin: 0; }
.detail-list > div { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid #f1f5f9; }
.detail-list > div:last-child { border-bottom: none; }
.detail-list dt { width: 130px; flex: none; color: var(--muted); font-size: 13.5px; }
.detail-list dd { margin: 0; font-size: 14px; word-break: break-word; }
.danger-zone { border-color: #fecaca; }
.danger-zone h2 { color: var(--danger); }
.pagination { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 16px; color: var(--muted); font-size: 14px; }

/* ---------- Storage accounts ---------- */
.account-row { display: flex; gap: 14px; justify-content: space-between; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid #f1f5f9; flex-wrap: wrap; }
.account-row:last-child { border-bottom: none; }
.account-info { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.account-info small { word-break: break-all; }
.account-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.account-actions form { margin: 0; }
.inline-form { display: inline; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(160deg, #0f172a 0%, #312e81 55%, #4f46e5 100%); }
.auth-card { background: #fff; border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, .35); padding: 32px; width: 100%; max-width: 420px; }
.auth-logo { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; letter-spacing: -.5px; margin-bottom: 18px; }
.auth-card h1 { margin: 0 0 4px; font-size: 23px; }
.auth-sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.auth-hint { color: var(--muted); font-size: 12.5px; text-align: center; margin: 18px 0 0; line-height: 1.7; }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: 48px 24px; }
.empty-icon { display: inline-flex; width: 64px; height: 64px; border-radius: 18px; background: var(--primary-soft); color: var(--primary); align-items: center; justify-content: center; margin-bottom: 14px; }
.empty-icon .icon { width: 30px; height: 30px; }
.empty-state h2 { margin-bottom: 6px; }
.feature-list { margin: 0; padding-left: 18px; }
.feature-list li { margin-bottom: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .db-layout { grid-template-columns: 1fr; }
  .db-subnav { position: static; max-height: none; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; box-shadow: 20px 0 50px rgba(0, 0, 0, .25); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .main { margin-left: 0; }
  .hamburger { display: inline-flex; }
  .content { padding: 18px 16px 40px; }
  .topbar { padding: 14px 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .tab-select-wrap { margin-left: 0; }
}
@media (max-width: 560px) {
  .stat-grid, .stat-grid-2 { grid-template-columns: 1fr; }
  .db-stats { width: 100%; }
}
