/* Database Panel */

body.db-page { overflow: hidden; }

/* Navbar is position:fixed at var(--nav-height) — layout starts below it */
.db-layout {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────── */

.db-sidebar {
  width: 240px;
  min-width: 200px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.db-sidebar-top {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.db-sidebar-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  margin-bottom: 8px;
}

.db-sidebar-search {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  box-sizing: border-box;
}

.db-sidebar-search:focus {
  outline: none;
  border-color: var(--accent);
}

.db-sidebar-groups {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0 16px;
}

.db-group { margin-bottom: 2px; }

.db-group-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s;
}

.db-group-btn:hover { color: var(--text); }

.db-group-count {
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-3);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 20px;
  color: var(--text-3);
}

.db-group-arrow {
  font-size: 10px;
  color: var(--text-3);
  margin-right: 4px;
  transition: transform 0.15s;
}

.db-group-arrow.open { transform: rotate(90deg); }

.db-table-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px 6px 24px;
  font-size: 13px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-2);
  text-align: left;
  transition: background 0.1s, color 0.1s;
}

.db-table-btn:hover {
  background: var(--bg-3);
  color: var(--text);
}

.db-table-btn.active {
  background: var(--accent-dim);
  color: var(--accent-2);
  font-weight: 600;
}

.db-table-btn .db-row-count {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 400;
}

.db-table-btn.active .db-row-count { color: var(--accent); }

/* ── Main area ───────────────────────────────── */

.db-main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* Empty / welcome state */
.db-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  gap: 12px;
}

.db-empty-state svg { opacity: 0.3; }

.db-empty-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-2);
}

.db-empty-sub { font-size: 14px; }

/* Stats grid on empty state */
.db-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  max-width: 640px;
  width: 100%;
  padding: 24px;
}

.db-stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  text-align: center;
}

.db-stat-value {
  font-size: 22px;
  font-weight: 900;
  color: var(--accent-2);
}

.db-stat-label {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Table view */
.db-table-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.db-table-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}

.db-table-header h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
}

.db-table-meta {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 3px;
}

.db-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.db-search {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text);
  width: 220px;
}

.db-search:focus {
  outline: none;
  border-color: var(--accent);
}

/* Column chips */
.db-col-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 9px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.db-col-chip {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-family: monospace;
  white-space: nowrap;
}

.db-col-chip.is-pk {
  border-color: var(--accent);
  color: var(--accent-2);
  background: var(--accent-dim);
}

/* Data table */
.db-table-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
}

.db-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.db-table th {
  background: var(--bg-2);
  border-bottom: 2px solid var(--border);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  z-index: 2;
}

.db-table th:hover { color: var(--text); }
.db-table th.sorted { color: var(--accent-2); }

.db-sort-arrow {
  display: inline-block;
  margin-left: 4px;
  font-size: 11px;
}

.db-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  max-width: 240px;
}

.db-table tr:hover td { background: var(--bg-2); }

.db-cell {
  display: block;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  cursor: default;
}

.db-cell.is-null {
  color: var(--text-3);
  font-style: italic;
}

.db-cell.is-bool-true  { color: var(--success); font-weight: 600; }
.db-cell.is-bool-false { color: var(--danger);  font-weight: 600; }

.db-cell.is-json {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-2);
}

.db-cell.is-date { color: var(--text-2); }

/* Action column */
.db-action-col {
  white-space: nowrap;
  min-width: 110px;
  position: sticky;
  right: 0;
  background: var(--bg);
  z-index: 1;
  border-left: 1px solid var(--border);
}

.db-table tr:hover .db-action-col { background: var(--bg-2); }
.db-action-col th {
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  z-index: 3;
}

.db-row-actions {
  display: flex;
  gap: 5px;
}

/* Pagination */
.db-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
  font-size: 13px;
  gap: 12px;
}

.db-pagination-info { color: var(--text-2); }

.db-page-btns {
  display: flex;
  gap: 5px;
  align-items: center;
}

.db-page-btn {
  padding: 5px 12px;
  font-size: 13px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  cursor: pointer;
}

.db-page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-2); }
.db-page-btn:disabled { opacity: 0.4; cursor: default; }
.db-page-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent-2); font-weight: 600; }

.db-page-current {
  font-size: 13px;
  color: var(--text-2);
  padding: 0 4px;
}

/* Loading state */
.db-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-3);
  font-size: 14px;
  gap: 8px;
}

/* ── Edit / Create Modal ─────────────────────── */

.db-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.db-modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: calc(var(--r) * 1.5);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.db-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.db-modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.db-modal-body {
  overflow-y: auto;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.db-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.db-field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
}

.db-field-type {
  font-size: 11px;
  font-weight: 400;
  font-family: monospace;
  color: var(--text-3);
}

.db-field-pk-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--accent-2);
  border: 1px solid var(--accent);
}

.db-field input,
.db-field textarea,
.db-field select {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 11px;
  font-size: 14px;
  color: var(--text);
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
}

.db-field textarea {
  resize: vertical;
  min-height: 80px;
  font-family: monospace;
  font-size: 13px;
}

.db-field input:focus,
.db-field textarea:focus,
.db-field select:focus {
  outline: none;
  border-color: var(--accent);
}

.db-field input[readonly] {
  opacity: 0.5;
  cursor: not-allowed;
}

.db-field-hint {
  font-size: 11px;
  color: var(--text-3);
}

.db-modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Confirm / password modals */
.db-confirm-modal { max-width: 420px; }
.db-pass-modal    { max-width: 420px; }

.db-confirm-body {
  padding: 20px 22px;
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
}

.db-confirm-body strong { color: var(--text); font-family: monospace; }

.db-pass-body {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.db-pass-desc {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.5;
}

.db-pass-error {
  font-size: 13px;
  color: var(--danger);
  margin-top: 4px;
}

/* Empty rows state */
.db-no-rows {
  text-align: center;
  padding: 48px;
  color: var(--text-3);
  font-size: 14px;
}

/* Responsive */
@media (max-width: 700px) {
  .db-sidebar { width: 170px; min-width: 140px; }
  .db-table-header { flex-direction: column; gap: 8px; }
  .db-search { width: 100%; }
  .db-col-strip { display: none; }
}
