/* Тёмная тема админки */
:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a303c;
  --text: #e6e8ee;
  --muted: #8a93a6;
  --accent: #4f8cff;
  --accent-hover: #6a9fff;
  --danger: #ff6b6b;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 6px; font-weight: 600; color: var(--text); }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }

/* Кнопки и поля */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 8px;
  padding: 9px 16px; font: inherit; font-weight: 500; cursor: pointer;
  color: var(--text); background: var(--panel-2);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 15px;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.alert {
  background: rgba(255, 107, 107, .1); border: 1px solid rgba(255, 107, 107, .4);
  color: var(--danger); border-radius: 8px; padding: 10px 12px;
}
.badge {
  font-size: 11px; padding: 1px 6px; border-radius: 6px; white-space: nowrap;
  background: rgba(79, 140, 255, .15); color: var(--accent);
}

/* Вход */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 16px; padding: 28px; }
.login-head { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700;
}

/* Каркас: меню слева, содержимое справа */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; font-size: 16px; padding: 4px 8px 16px; }
.brand:hover { color: var(--text); }
.menu { display: grid; gap: 2px; }
.menu-item { color: var(--muted); padding: 8px 10px; border-radius: 8px; }
.menu-item:hover { color: var(--text); background: var(--panel-2); }
.menu-item.active { color: var(--text); background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding: 12px 8px 0; border-top: 1px solid var(--border); }
.who { color: var(--muted); font-size: 13px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 24px; border-bottom: 1px solid var(--border); }
.menu-toggle { display: none; }
.content { padding: 24px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 14px; }
.tile { color: var(--muted); position: relative; transition: border-color .15s; }
.tile:hover { border-color: var(--accent); color: var(--muted); }
.soon { position: absolute; top: 14px; right: 14px; font-size: 11px; color: var(--muted); }
.empty { max-width: 640px; }

/* Телефон: меню выезжает по кнопке */
@media (max-width: 760px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .topbar, .content { padding: 14px 16px; }
}

/* ---------- Шаг 2: списки, формы, раздел «База» ---------- */
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.mt { margin-top: 20px; }
.pad { padding: 4px 10px; }
.ok { color: #4cd48a; }
.warn { color: #f5b44a; }
.err { color: var(--danger); }
.null { color: #5d6678; font-style: italic; font-size: 12px; }
.danger { color: var(--danger) !important; }
.badge-ro { background: rgba(245, 180, 74, .14); color: #f5b44a; }
.badge-rw { background: rgba(76, 212, 138, .14); color: #4cd48a; }
.kbd { font-size: 11px; opacity: .75; margin-left: 6px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar p { margin: 0; }
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
table.list th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.list td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
td.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
td.actions form { margin: 0; }
tr.test-row td { background: var(--bg); }
pre.grants, pre.create-sql {
  margin: 8px 0 0; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; font: 12px/1.5 ui-monospace, Consolas, monospace; color: var(--muted);
  white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto;
}

.form-card { max-width: 560px; display: grid; gap: 14px; }
.row { display: flex; gap: 12px; }
.row .grow { flex: 1; }
.row .w-port { width: 110px; }
label.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px; }
label.check input { width: auto; }
label.inline { display: inline-flex; align-items: center; gap: 6px; }
label.inline select { width: auto; padding: 5px 8px; font-size: 13px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Раздел «База» */
.content:has(.db-layout) { padding: 16px; }
.db-layout { display: grid; grid-template-columns: var(--tree-w, 280px) 8px minmax(0, 1fr); gap: 6px; align-items: start; }
.tree { padding: 8px; max-height: calc(100vh - 110px); overflow: auto; position: sticky; top: 16px; }
.node-head {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  background: none; border: 0; color: var(--text); font: inherit; font-size: 13px;
  padding: 5px 8px; border-radius: 6px; cursor: pointer;
}
.node-head:hover { background: var(--panel-2); }
.node-head .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-head .caret {
  color: var(--muted); font-size: 15px; line-height: 1; width: 20px; height: 20px; flex-shrink: 0;
  display: inline-grid; place-items: center; border-radius: 4px; transition: transform .15s;
}
.node-head .caret:hover { color: var(--text); background: rgba(255, 255, 255, .06); }
.node-head.open > .caret { transform: rotate(90deg); }
.node-head.conn { font-weight: 600; }
.node-head.table { padding-left: 34px; color: var(--muted); }
.node-head.table:hover { color: var(--text); }
.node-head.table.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.node-head .count { font-size: 11px; color: #5d6678; }
.kids { padding-left: 12px; }

.db-main { min-width: 0; }
.db-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.crumbs { font-size: 14px; }
.tabs { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.tabs button { background: none; border: 0; color: var(--muted); font: inherit; font-size: 14px; font-weight: 500; padding: 7px 20px; border-radius: 6px; cursor: pointer; }
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--accent); color: #fff; }
.grid-info { margin: 0 0 8px; min-height: 18px; }
.sql-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.CodeMirror { height: 190px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; margin-bottom: 10px; }
.CodeMirror-empty { color: #5d6678; }

/* Tabulator под нашу палитру. Префикс .db-main — чтобы перебить тему midnight, которая подключается позже */
.db-main .tabulator { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.db-main .tabulator .tabulator-header { background: var(--panel-2); border-bottom: 1px solid var(--border); color: var(--text); }
.db-main .tabulator .tabulator-header .tabulator-col { background: var(--panel-2); border-right: 1px solid var(--border); }
.db-main .tabulator .tabulator-header .tabulator-col input { background: var(--bg); border: 1px solid var(--border); border-radius: 5px; color: var(--text); padding: 3px 6px; font-size: 12px; }
.db-main .tabulator .tabulator-tableholder { background: var(--panel); }
.db-main .tabulator-row { background: var(--panel); color: var(--text); border-bottom: 1px solid #20252f; }
.db-main .tabulator-row.tabulator-row-even { background: #1a1d25; }
.db-main .tabulator-row.tabulator-selectable:hover, .db-main .tabulator-row:hover { background: #222834; }
.db-main .tabulator-row .tabulator-cell { border-right: 1px solid #20252f; }
.db-main .tabulator-row .tabulator-cell.col-pk { color: var(--accent); }
.db-main .tabulator .tabulator-footer { background: var(--panel-2); border-top: 1px solid var(--border); color: var(--muted); }
.db-main .tabulator .tabulator-footer .tabulator-page { background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 5px; }
.db-main .tabulator .tabulator-footer .tabulator-page.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.db-main .tabulator .tabulator-footer select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 5px; width: auto; padding: 2px 6px; font-size: 12px; }
.db-main .tabulator .tabulator-placeholder span { color: var(--muted) !important; font-size: 14px !important; }


@media (max-width: 760px) {
  .db-layout { grid-template-columns: 1fr; }
  .resizer { display: none; }
  .tree { position: static; max-height: 260px; }
  .row { flex-direction: column; }
  .row .w-port { width: 100%; }
}

/* ---------- 11.09.2026: правки по отзыву ---------- */
.resizer { align-self: stretch; min-height: 200px; cursor: col-resize; border-radius: 4px; position: sticky; top: 16px; height: calc(100vh - 110px); }
.resizer::after { content: ""; display: block; width: 2px; height: 40px; margin: 40vh auto 0; background: var(--border); border-radius: 2px; }
.resizer:hover::after { background: var(--accent); }
.tree-search { font-size: 13px; padding: 6px 10px; margin-bottom: 6px; }
.tree-hint { margin: 10px 6px 2px; line-height: 1.4; }
.node-head.table { padding-left: 18px; }
.node-head.table .caret { cursor: pointer; padding: 2px; margin: -2px; }
.node-head.table .caret.open { transform: rotate(90deg); }
.node-head.column { padding-left: 48px; color: var(--muted); font-size: 12px; cursor: default; user-select: none; }
.node-head.column:hover { color: var(--text); }
.node-head.column .count { font-family: ui-monospace, Consolas, monospace; }
.kids.cols { padding-left: 0; }
.guard { max-width: 620px; margin-bottom: 12px; }
.hint { border-bottom: 1px dotted var(--muted); cursor: help; }
.notice { background: rgba(76, 212, 138, .1); border: 1px solid rgba(76, 212, 138, .35); color: #4cd48a; border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
tr.just-saved td { background: rgba(76, 212, 138, .06); }
button.copy { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0 4px; }
button.copy:hover { color: var(--accent); }
.test-box { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.sql-result-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.sql-result-bar .grid-info { margin: 0; }
.sql-export { display: flex; gap: 8px; }
/* Выделение в редакторе SQL — заметное */
.cm-s-material-darker .CodeMirror-selected,
.cm-s-material-darker.CodeMirror-focused .CodeMirror-selected { background: rgba(79, 140, 255, .45) !important; }
.cm-s-material-darker .CodeMirror-line::selection,
.cm-s-material-darker .CodeMirror-line > span::selection,
.cm-s-material-darker .CodeMirror-line > span > span::selection { background: rgba(79, 140, 255, .45); }
.cm-s-material-darker .CodeMirror-cursor { border-left: 2px solid #fff; }

/* ---------- 11.09.2026: кнопки крупнее, подсказки SQL, изменяемая высота ---------- */
.btn-soft { background: rgba(79, 140, 255, .14); color: #8fb6ff; border-color: rgba(79, 140, 255, .35); }
.btn-soft:hover { background: rgba(79, 140, 255, .24); color: #fff; }
.btn-md { padding: 7px 14px; font-size: 14px; }
.sql-bar label.inline { font-size: 14px; }
.sql-bar label.inline select { font-size: 14px; padding: 6px 10px; }
.sql-snippets { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; align-items: center; }
.chip {
  background: var(--panel-2); border: 1px solid var(--border); color: #c3cad8; border-radius: 6px;
  font: 12px/1 ui-monospace, Consolas, monospace; padding: 6px 8px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: #fff; }
.chip.kw { color: #c792ea; }
.chip.fn { color: #82aaff; }
select.templates { width: auto; font-size: 13px; padding: 5px 8px; margin-right: 6px; }
.hsplit { height: 10px; cursor: row-resize; margin: -4px 0 4px; position: relative; }
.hsplit::after { content: ""; position: absolute; left: 50%; top: 4px; width: 48px; height: 3px; margin-left: -24px; border-radius: 2px; background: var(--border); }
.hsplit:hover::after, .hsplit.dragging::after { background: var(--accent); }
.CodeMirror { margin-bottom: 0; }
/* Всплывающие подсказки редактора (addon show-hint) в тёмной теме */
body .CodeMirror-hints { background: var(--panel-2); border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0,0,0,.45); font: 13px ui-monospace, Consolas, monospace; z-index: 50; border-radius: 6px; padding: 3px; max-height: 260px; }
body .CodeMirror-hint { color: var(--text); padding: 3px 8px; border-radius: 4px; }
body li.CodeMirror-hint-active { background: var(--accent); color: #fff; }

/* ---------- Шаг 3: правка строк ---------- */
.data-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.edit-actions { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.db-main .grid-editing.tabulator { border-color: rgba(79, 140, 255, .6); box-shadow: 0 0 0 1px rgba(79, 140, 255, .25); }
.db-main .tabulator-row .tabulator-cell.cell-dirty { background: rgba(245, 180, 74, .22); color: #ffd58a; }
.db-main .tabulator-row .tabulator-cell.tabulator-editing { background: var(--bg); border: 1px solid var(--accent); }
.db-main .tabulator-row .tabulator-cell.tabulator-editing input,
.db-main .tabulator-row .tabulator-cell.tabulator-editing textarea { background: var(--bg); color: var(--text); font-size: 13px; padding: 2px 4px; border: 0; border-radius: 0; }
.db-main .tabulator-row.tabulator-selected { background: rgba(255, 107, 107, .12); }
/* Пока есть несохранённые правки — нельзя листать, сортировать и фильтровать (правки бы потерялись) */
.db-main .grid-dirty .tabulator-footer,
.db-main .grid-dirty .tabulator-header .tabulator-col { pointer-events: none; opacity: .45; }
.tabulator-menu { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; }
.tabulator-menu .tabulator-menu-item:hover { background: var(--accent) !important; color: #fff; }
.row-dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: min(640px, 92vw); max-height: 86vh; }
.row-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.row-fields { display: grid; gap: 10px; margin: 12px 0; max-height: 58vh; overflow: auto; padding-right: 4px; }
.row-field { display: grid; gap: 4px; }
.row-field input, .row-field select, .row-field textarea { font-size: 14px; padding: 7px 10px; }
.row-field input:disabled, .row-field textarea:disabled { opacity: .4; }
.row-field label.check { font-size: 12px; color: var(--muted); gap: 6px; }
