:root {
  --bg: #0a0c10;
  --bg-soft: #10131a;
  --panel: #141821;
  --panel-2: #171c26;
  --border: #262d3a;
  --text: #f2f4f8;
  --muted: #8993a4;
  --accent: #8b5cf6;
  --accent-2: #6d4ae2;
  --success: #2fd184;
  --warning: #f4b942;
  --danger: #ff5f68;
  --shadow: 0 18px 45px rgba(0,0,0,.3);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 25% 15%, rgba(139,92,246,.18), transparent 30%),
    radial-gradient(circle at 80% 75%, rgba(79,70,229,.12), transparent 34%),
    var(--bg);
}

.login-card {
  width: min(430px, 100%);
  background: rgba(20,24,33,.94);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.login-card h1 { margin: 30px 0 8px; font-size: 28px; }
.login-form { display: grid; gap: 18px; margin-top: 26px; }
.login-form label { display: grid; gap: 8px; color: #cfd5df; font-size: 13px; }

input, textarea, select {
  border: 1px solid var(--border);
  background: #0f131a;
  color: var(--text);
  border-radius: 10px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: #6650c9; box-shadow: 0 0 0 3px rgba(139,92,246,.12); }
.login-form input { height: 46px; padding: 0 13px; }

.form-error {
  margin-top: 16px;
  border: 1px solid rgba(255,95,104,.28);
  background: rgba(255,95,104,.08);
  color: #ff8c93;
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 13px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 12px; font-weight: 900; font-size: 20px;
  background: linear-gradient(145deg, #9969ff, #5d42ca);
  box-shadow: 0 7px 22px rgba(139,92,246,.24);
}
.brand-title { font-weight: 800; letter-spacing: .2px; }
.brand-subtitle { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.3px; margin-top: 2px; }

.app { min-height: 100vh; display: grid; grid-template-columns: 235px 1fr; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 235px;
  background: #0d1016; border-right: 1px solid var(--border);
  padding: 22px 16px; display: flex; flex-direction: column; z-index: 10;
}
.sidebar .brand { padding: 2px 8px 24px; }
.nav { display: grid; gap: 5px; }
.nav-item {
  width: 100%; border: 0; background: transparent; color: var(--muted);
  text-align: left; padding: 11px 12px; border-radius: 10px; font-weight: 650;
}
.nav-item:hover { color: var(--text); background: rgba(255,255,255,.035); }
.nav-item.active { color: #fff; background: rgba(139,92,246,.14); box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-footer { margin-top: auto; }
.admin-box { display: flex; align-items: center; justify-content: space-between; padding: 12px; background: #121720; border: 1px solid var(--border); border-radius: 12px; }
.admin-name { font-size: 13px; font-weight: 700; max-width: 145px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.workspace { grid-column: 2; min-width: 0; padding: 0 28px 36px; }
.topbar {
  height: 90px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 8;
  background: linear-gradient(to bottom, rgba(10,12,16,.98) 70%, rgba(10,12,16,0));
}
.topbar h2 { margin: 0 0 4px; font-size: 23px; }
.connection { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.dot { width: 7px; height: 7px; background: var(--success); border-radius: 50%; display: inline-block; box-shadow: 0 0 10px rgba(47,209,132,.6); }

.page { display: none; }
.page.active { display: block; }

.btn {
  border: 1px solid transparent; border-radius: 10px; padding: 9px 14px;
  color: #fff; background: #222936; font-weight: 700; font-size: 13px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.success { background: rgba(47,209,132,.14); border-color: rgba(47,209,132,.25); color: #75e7ad; }
.btn.warning { background: rgba(244,185,66,.13); border-color: rgba(244,185,66,.25); color: #ffd071; }
.btn.danger { background: rgba(255,95,104,.12); border-color: rgba(255,95,104,.25); color: #ff8b92; }
.btn.ghost { background: #141922; border-color: var(--border); color: #c7ced9; }
.btn.wide { width: 100%; padding: 12px; }
.small-btn { padding: 7px 10px; font-size: 12px; }
.icon-button { width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--border); color: #c5ccd6; background: #11161e; display: grid; place-items: center; }

.status-hero {
  min-height: 145px; background:
    linear-gradient(120deg, rgba(139,92,246,.15), rgba(20,24,33,.94) 52%),
    var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: space-between; padding: 26px;
}
.eyebrow { color: #a993ff; font-size: 11px; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: 10px; }
.server-state-line { display: flex; align-items: center; gap: 11px; font-size: 24px; margin-bottom: 7px; }
.big-dot { width: 12px; height: 12px; background: #697386; border-radius: 50%; }
.big-dot.online { background: var(--success); box-shadow: 0 0 14px rgba(47,209,132,.55); }
.big-dot.offline { background: var(--danger); box-shadow: 0 0 14px rgba(255,95,104,.38); }
.server-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 14px 0; }
.stat-card { border: 1px solid var(--border); background: var(--panel); border-radius: 14px; padding: 18px; min-width: 0; }
.stat-label { color: var(--muted); font-size: 12px; margin-bottom: 9px; }
.stat-value { font-size: 25px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-value-small { font-size: 15px; line-height: 30px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 14px; }
.panel-head h3 { margin: 0 0 4px; font-size: 16px; }
.compact-head { margin-bottom: 12px; }

.terminal {
  margin: 0; background: #090b0f; border: 1px solid #1e2430; border-radius: 11px;
  color: #b7c0ce; padding: 14px; overflow: auto; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
}
.compact-terminal { height: 300px; }
.live-terminal { height: calc(100vh - 190px); min-height: 440px; }
.full-height-panel { min-height: calc(100vh - 122px); }
.badge { display: inline-flex; align-items: center; border: 1px solid var(--border); background: #11161d; color: var(--muted); padding: 6px 9px; border-radius: 999px; font-size: 11px; }
.badge.live { color: #71e5a9; border-color: rgba(47,209,132,.25); background: rgba(47,209,132,.08); }
.row-actions { display: flex; align-items: center; gap: 8px; }

.db-layout { display: grid; grid-template-columns: 245px minmax(0,1fr); gap: 14px; min-height: calc(100vh - 125px); }
.tables-panel { min-height: calc(100vh - 125px); padding: 14px; }
.tables-list { display: grid; gap: 3px; margin-top: 10px; max-height: calc(100vh - 245px); overflow: auto; }
.table-item { border: 0; background: transparent; color: #aab3c1; text-align: left; padding: 8px 9px; border-radius: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.table-item:hover { background: rgba(255,255,255,.035); color: #fff; }
.table-item.active { background: rgba(139,92,246,.13); color: #d8ccff; }
.search-input { width: 100%; height: 38px; padding: 0 11px; }
.db-content { min-width: 0; min-height: calc(100vh - 125px); }
.db-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.grow { flex: 1; }
.db-toolbar select { height: 38px; padding: 0 9px; }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { position: sticky; top: 0; background: #11161e; color: #909aaa; text-align: left; padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; z-index: 2; }
td { padding: 9px 10px; border-bottom: 1px solid rgba(38,45,58,.72); color: #c9d0da; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255,255,255,.018); }
.cell-null { color: #596373; font-style: italic; }
.action-cell { display: flex; gap: 5px; }
.mini-action { border: 1px solid var(--border); background: #10151d; color: #aeb7c3; border-radius: 7px; padding: 4px 7px; font-size: 11px; }
.mini-action.danger { color: #ff858d; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 12px; }
.structure-details { margin-top: 14px; color: #c9d0da; }
.structure-details summary { cursor: pointer; color: #aeb7c3; font-size: 12px; }
.structure-grid { display: grid; gap: 7px; margin-top: 12px; }
.structure-row { display: grid; grid-template-columns: 180px 180px 80px 1fr; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 11px; }
.empty-state { min-height: 450px; display: grid; place-items: center; align-content: center; text-align: center; }
.empty-state h3 { margin: 13px 0 4px; }
.empty-icon { width: 60px; height: 60px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 18px; color: #8d79df; font-weight: 900; background: rgba(139,92,246,.07); }

.sql-input { width: 100%; min-height: 210px; padding: 14px; resize: vertical; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.sql-toolbar { display: flex; align-items: center; justify-content: space-between; margin: 12px 0; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #aab3bf; }
.check-row input { accent-color: var(--accent); }
.sql-meta { margin-bottom: 8px; }
.sql-results-wrap { max-height: 460px; }
#auditTable td:last-child { max-width: 420px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.68); display: grid; place-items: center; padding: 20px; }
.modal-card { width: min(720px, 100%); max-height: 86vh; overflow: auto; background: #141922; border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.field-grid { display: grid; gap: 10px; }
.field-row { display: grid; grid-template-columns: 180px minmax(0,1fr); gap: 10px; align-items: center; }
.field-row label { font-size: 12px; color: #aab3bf; overflow: hidden; text-overflow: ellipsis; }
.field-row input { height: 38px; padding: 0 10px; width: 100%; }
.field-row textarea { min-height: 70px; padding: 9px 10px; width: 100%; resize: vertical; }

.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 100;
  max-width: 420px; background: #171d27; border: 1px solid var(--border); border-radius: 11px;
  box-shadow: var(--shadow); padding: 11px 14px; color: #d7dde6; font-size: 12px;
  transform: translateY(20px); opacity: 0; pointer-events: none; transition: .2s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { border-color: rgba(255,95,104,.35); color: #ff9aa0; }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .db-layout { grid-template-columns: 210px minmax(0,1fr); }
}
@media (max-width: 760px) {
  .app { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 14px; }
  .nav { grid-template-columns: repeat(5, minmax(0,1fr)); overflow-x: auto; }
  .nav-item { text-align: center; padding: 9px 7px; font-size: 11px; }
  .sidebar-footer { margin-top: 12px; }
  .workspace { padding: 0 14px 24px; }
  .topbar { height: 76px; position: static; }
  .status-hero { align-items: flex-start; flex-direction: column; gap: 20px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .db-layout { grid-template-columns: 1fr; }
  .tables-panel { min-height: 0; }
  .tables-list { max-height: 210px; }
  .structure-row { grid-template-columns: 1fr 1fr; }
}
