:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --bg-3: #1c232d;
  --panel: #12171e;
  --border: #263140;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #e0a83d;
  --accent-2: #4a9eff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
a { color: var(--accent-2); text-decoration: none; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #30363d; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Login ---------- */
#login-view {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 16px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 14px; padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-card .brand { text-align: center; margin-bottom: 22px; }
.login-card .brand h1 { margin: 0; font-size: 22px; letter-spacing: .5px; }
.login-card .brand .accent { color: var(--accent); }
.login-card .brand p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 11px 12px; background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-3); color: var(--text); font-weight: 600; font-size: 13px;
  transition: .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #201a08; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); border-color: #4d2222; }
.btn.danger:hover { background: #2a1515; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.msg { font-size: 12px; margin-top: 10px; min-height: 16px; }
.msg.err { color: var(--red); }
.msg.ok { color: var(--green); }

/* ---------- App shell ---------- */
#app-view { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0;
}
.sidebar .logo { padding: 20px 20px 14px; font-size: 18px; font-weight: 700; letter-spacing: .5px; }
.sidebar .logo .accent { color: var(--accent); }
.sidebar .logo small { display:block; color: var(--muted); font-size: 11px; font-weight: 400; margin-top:2px;}
.nav { flex: 1; padding: 8px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: var(--muted); font-weight: 500; margin-bottom: 2px; cursor: pointer;
}
.nav a:hover { background: var(--bg-2); color: var(--text); }
.nav a.active { background: var(--bg-3); color: var(--accent); }
.nav a .ico { width: 18px; text-align: center; }
.sidebar .foot { padding: 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.sidebar .foot .user { color: var(--text); font-weight: 600; margin-bottom: 8px; }

.main { flex: 1; margin-left: 220px; min-width: 0; }
.topbar {
  height: 56px; border-bottom: 1px solid var(--border); background: var(--bg);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 16px; font-weight: 600; }
.topbar .status-dot { font-size: 12px; color: var(--muted); }
.content { padding: 24px; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px;
}
.card h3 { margin: 0 0 4px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }
.card .big { font-size: 26px; font-weight: 700; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.bar { height: 6px; background: var(--bg-3); border-radius: 4px; margin-top: 10px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .4s; }
.bar.warn > span { background: var(--yellow); }
.bar.crit > span { background: var(--red); }

.section-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin: 26px 0 12px; font-weight: 600; }

.srv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 12px; }
.srv {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; display: flex; align-items: center; gap: 12px;
}
.srv .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.srv .dot.up { background: var(--green); box-shadow: 0 0 8px var(--green); }
.srv .dot.down { background: var(--red); }
.srv .n { font-weight: 600; }
.srv .m { color: var(--muted); font-size: 12px; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { background: var(--bg-2); position: sticky; top: 0; color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; z-index:1;}
table.data th:hover { color: var(--accent); }
table.data td { max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
table.data tr:hover td { background: var(--bg-2); }
.pk { color: var(--accent); }

/* ---------- DB browser layout ---------- */
.db-layout { display: grid; grid-template-columns: 200px 260px 1fr; gap: 14px; align-items: start; }
.list-panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); max-height: 72vh; overflow: auto; }
.list-panel .lp-head { padding: 10px 12px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); }
.list-panel .item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid rgba(38,49,64,.5); font-size: 13px; }
.list-panel .item:hover { background: var(--bg-2); }
.list-panel .item.active { background: var(--bg-3); color: var(--accent); }
.list-panel .item .meta { color: var(--muted); font-size: 11px; margin-top: 2px; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=text], .toolbar select {
  padding: 8px 10px; background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.toolbar input[type=text]:focus { border-color: var(--accent); }
.pager { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

/* ---------- Console ---------- */
.console {
  background: #05070a; border: 1px solid var(--border); border-radius: var(--radius);
  font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px;
  padding: 12px 14px; height: 66vh; overflow: auto; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
}
.console .l { color: #c9d1d9; }
.console .l.warn { color: #e3b341; }
.console .l.err { color: #ff7b72; }
.console .l.info { color: #79c0ff; }
.console .l.debug { color: #6e7681; }

/* ---------- Settings ---------- */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button { background: none; border: none; color: var(--muted); padding: 10px 14px; font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
textarea.code {
  width: 100%; min-height: 52vh; background: #05070a; color: #c9d1d9; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5; outline: none; resize: vertical;
}
textarea.code:focus { border-color: var(--accent); }
.out {
  background: #05070a; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; font-family: ui-monospace, monospace; font-size: 12px; white-space: pre-wrap;
  max-height: 40vh; overflow: auto; margin-top: 12px; color: #c9d1d9;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.mb { margin-bottom: 14px; }
.inp {
  padding: 9px 11px; background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.inp:focus { border-color: var(--accent); }
.notice { background: #1a1e12; border: 1px solid #3a3417; color: #d9c98a; padding: 10px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 14px; }

.spinner { display:inline-block; width:14px; height:14px; border:2px solid var(--border); border-top-color: var(--accent); border-radius:50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--bg-3); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 50; font-size: 13px; opacity: 0; transform: translateY(10px); transition: .25s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { border-color: #22432a; }
.toast.err { border-color: #4d2222; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: .2s; z-index: 20; }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .db-layout { grid-template-columns: 1fr; }
  .menu-btn { display: inline-flex !important; }
}
.menu-btn { display: none; }

/* ---------- select2 dark theme ---------- */
.select2-container--default .select2-selection--single {
  background: var(--bg-2) !important; border: 1px solid var(--border) !important; height: 38px !important; border-radius: 8px !important;
}
.select2-container--default .select2-selection--single .select2-selection__rendered { color: var(--text) !important; line-height: 38px !important; }
.select2-container--default .select2-selection--single .select2-selection__placeholder { color: var(--muted) !important; }
.select2-container--default .select2-selection--single .select2-selection__arrow { height: 36px !important; }
/* dropdown panel + results list: dark background */
.select2-container--default .select2-dropdown,
.select2-dropdown { background: var(--bg-2) !important; border: 1px solid var(--border) !important; color: var(--text) !important; }
.select2-results, .select2-results__options { background: var(--bg-2) !important; }
.select2-container--default .select2-results__option { color: var(--text) !important; background: var(--bg-2) !important; }
.select2-container--default .select2-results__option--highlighted,
.select2-container--default .select2-results__option--highlighted[aria-selected] { background: var(--accent) !important; color: #201a08 !important; }
.select2-container--default .select2-results__option[aria-selected=true],
.select2-container--default .select2-results__option[data-selected=true] { background: var(--bg-3) !important; color: var(--text) !important; }
.select2-results__option { padding: 8px 10px !important; }
/* search box inside dropdown */
.select2-search--dropdown { background: var(--bg-2) !important; padding: 8px !important; }
.select2-search--dropdown .select2-search__field {
  background: var(--bg-3) !important; color: var(--text) !important;
  border: 1px solid var(--border) !important; border-radius: 6px !important; padding: 7px 9px !important;
}
.select2-results__option .loading-results, .select2-results__message { color: var(--muted) !important; }
