/* ── Variables ── */
:root {
  --bg-body: #0a0a0f;
  --bg-surface: #111118;
  --bg-card: #16161f;
  --bg-hover: #1c1c28;
  --bg-active: #1f1f2e;
  --bg-input: #111118;
  --border: #25253a;
  --border-focus: #4f46e5;
  --text-primary: #e8e8f0;
  --text-secondary: #9898b0;
  --text-muted: #5a5a78;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-dim: rgba(99, 102, 241, 0.12);
  --success: #22c55e;
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.12);
  --warning: #f59e0b;
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Login ── */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh;
  background: radial-gradient(ellipse at 50% 30%, rgba(99,102,241,0.08) 0%, transparent 60%);
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.login-icon {
  color: var(--accent);
  margin-bottom: 16px;
}
.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}
.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}
.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text-primary);
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
  text-align: center;
}
.login-card input:focus { border-color: var(--accent); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 20px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font);
  font-size: 13px; font-weight: 600;
  border: none; border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.15s;
  padding: 8px 14px;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent); color: white;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
  background: transparent; color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger:hover { color: var(--danger) !important; }
.btn-full { width: 100%; justify-content: center; padding: 12px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { font-size: 20px; padding: 4px 10px; line-height: 1; }

/* ── Header ── */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-title { font-size: 15px; font-weight: 700; }
.header-badge {
  font-size: 11px; font-weight: 500;
  padding: 3px 10px; border-radius: 20px;
  background: var(--accent-dim); color: var(--accent);
  font-family: var(--mono);
}
.header-right { display: flex; align-items: center; gap: 4px; }

/* ── Layout ── */
.app { display: flex; flex-direction: column; height: 100dvh; }
.layout { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: 240px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 10px;
}
.sidebar-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.sidebar-count {
  font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 10px; background: var(--bg-hover); color: var(--text-secondary);
}
.table-list { display: flex; flex-direction: column; gap: 2px; padding: 0 8px 16px; }
.table-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.12s;
  border: 1px solid transparent;
}
.table-item:hover { background: var(--bg-hover); }
.table-item.active { background: var(--accent-dim); border-color: var(--accent); }
.table-item-name { font-size: 13px; font-weight: 600; }
.table-item.active .table-item-name { color: var(--accent); }
.table-item-count {
  font-size: 11px; color: var(--text-muted); font-weight: 500;
  font-family: var(--mono);
}

/* ── Main ── */
.main { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; gap: 16px; color: var(--text-muted); font-size: 14px;
}

/* ── Table Toolbar ── */
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.toolbar-left { display: flex; align-items: center; gap: 12px; }
.toolbar-right { display: flex; align-items: center; gap: 10px; }
.table-name { font-size: 16px; font-weight: 700; font-family: var(--mono); }
.row-count { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.search-input {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 12px;
  font-size: 13px; color: var(--text-primary); font-family: var(--font);
  outline: none; width: 200px; transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--accent); }

/* ── Data Grid ── */
.data-grid-wrapper { flex: 1; overflow: auto; }
.data-grid {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.data-grid thead { position: sticky; top: 0; z-index: 2; }
.data-grid th {
  background: var(--bg-card);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: pointer;
  user-select: none;
}
.data-grid th:hover { color: var(--text-secondary); }
.data-grid th .sort-icon { margin-left: 4px; opacity: 0.4; }
.data-grid th.sorted .sort-icon { opacity: 1; color: var(--accent); }
.data-grid td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  max-width: 300px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-secondary);
}
.data-grid tr:hover td { background: var(--bg-hover); }
.data-grid td.cell-null { color: var(--text-muted); font-style: italic; }
.data-grid td.cell-json { color: var(--warning); }
.data-grid td.cell-number { color: var(--accent); }
.data-grid .row-actions {
  display: flex; gap: 4px; opacity: 0; transition: opacity 0.12s;
}
.data-grid tr:hover .row-actions { opacity: 1; }
.action-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 4px; border-radius: 4px;
  display: flex; align-items: center;
  transition: all 0.12s;
}
.action-btn:hover { background: var(--bg-active); color: var(--text-primary); }
.action-btn.delete:hover { color: var(--danger); background: var(--danger-dim); }

/* ── Pagination ── */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; border-top: 1px solid var(--border);
  flex-shrink: 0; font-size: 12px; color: var(--text-muted);
}
.pagination-btns { display: flex; gap: 6px; }
.page-btn {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 5px 12px;
  font-size: 12px; color: var(--text-secondary); font-family: var(--font);
  cursor: pointer; font-weight: 600;
}
.page-btn:hover { background: var(--bg-hover); }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── SQL View ── */
.sql-view { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.sql-editor-wrapper {
  padding: 16px 20px; display: flex; gap: 10px; align-items: flex-end;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sql-input {
  flex: 1; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
  font-family: var(--mono); font-size: 13px;
  color: var(--text-primary); resize: vertical;
  min-height: 80px; max-height: 200px; outline: none;
}
.sql-input:focus { border-color: var(--accent); }
.sql-result { flex: 1; overflow: auto; padding: 0; }
.sql-result .data-grid td,
.sql-result .data-grid th { padding: 8px 12px; }
.sql-error { padding: 20px; color: var(--danger); font-family: var(--mono); font-size: 13px; }
.sql-empty { padding: 20px; color: var(--text-muted); font-size: 13px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; width: 520px; max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body {
  padding: 20px 22px;
  overflow-y: auto; flex: 1;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 22px; border-top: 1px solid var(--border);
}
.field-group { display: flex; flex-direction: column; gap: 5px; }
.field-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
}
.field-label .pk-badge {
  font-size: 9px; background: var(--accent-dim); color: var(--accent);
  padding: 1px 6px; border-radius: 4px; font-weight: 700;
}
.field-label .type-badge {
  font-size: 9px; background: var(--bg-hover); color: var(--text-muted);
  padding: 1px 6px; border-radius: 4px; font-weight: 500;
  font-family: var(--mono);
}
.field-input {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px;
  font-size: 13px; color: var(--text-primary); font-family: var(--font);
  outline: none; transition: border-color 0.2s;
}
.field-input:focus { border-color: var(--accent); }
.field-input.is-pk { opacity: 0.6; }
textarea.field-input { min-height: 60px; font-family: var(--mono); font-size: 12px; resize: vertical; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 20px;
  font-size: 13px; font-weight: 600; z-index: 200;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  animation: toast-in 0.25s ease-out;
}
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

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

/* ── Confirm Dialog ── */
.confirm-dialog {
  text-align: center; padding: 10px 0;
}
.confirm-dialog p {
  font-size: 14px; color: var(--text-secondary);
  margin-bottom: 6px;
}
.confirm-dialog .confirm-id {
  font-family: var(--mono); font-size: 13px;
  color: var(--danger); font-weight: 600;
}
