:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-2: #fafafb;
  --text: #16181d;
  --text-2: #4a5060;
  --muted: #7b8191;
  --border: #e4e6eb;
  --border-2: #eceef2;
  --accent: #2f6bff;
  --accent-soft: #edf2ff;
  --accent-text: #ffffff;
  --green: #14a35a;
  --green-soft: #e7f7ee;
  --amber: #d98a00;
  --amber-soft: #fff4dc;
  --red: #e0413c;
  --red-soft: #fdecec;
  --violet: #7a4ff0;
  --violet-soft: #f1ecff;
  --grid-line: #e3e5ea;
  --grid-head: #f4f5f7;
  --sel-bg: rgba(47, 107, 255, .09);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --panel: #191b21; --panel-2: #1d2027; --text: #eceef3; --text-2: #b9bfcc; --muted: #868d9c;
    --border: #2a2e37; --border-2: #252831; --accent: #5b8bff; --accent-soft: #1e2a47;
    --green-soft: #13301f; --amber-soft: #352a10; --red-soft: #3a1918; --violet-soft: #2a2145;
    --grid-line: #2a2e37; --grid-head: #1f2229; --sel-bg: rgba(91, 139, 255, .16);
    --shadow: none; --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1 { font-size: 26px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
h3 { font-size: 15px; margin: 0; font-weight: 600; }
h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.h2 { font-size: 17px; margin: 28px 0 12px; }
.sub { color: var(--muted); margin: 6px 0 0; font-size: 13px; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.grow { flex: 1; }
.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--panel-2); border-color: #d3d6dd; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 7px;
  border: none; background: transparent; color: var(--muted); cursor: pointer; font: inherit; font-size: 16px;
}
.icon-btn:hover { background: var(--border-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; background: none; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------- каркас ---------- */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 0 8px 18px; }
.brand .i { width: 26px; height: 26px; padding: 5px; border-radius: 8px; background: var(--accent); color: #fff; stroke-width: 2.2; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .table-list li {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--text-2);
  text-decoration: none; cursor: pointer; font-weight: 500;
}
.nav a:hover, .table-list li:hover { background: var(--bg); color: var(--text); }
.nav a.active, .table-list li.active { background: var(--accent-soft); color: var(--accent); }
.side-label {
  display: flex; align-items: center; justify-content: space-between; margin: 20px 4px 6px 10px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600;
}
.side-search { position: relative; margin: 0 2px 6px; }
.side-search .i { position: absolute; left: 9px; top: 9px; width: 14px; height: 14px; color: var(--muted); }
.side-search input { width: 100%; padding-left: 30px; height: 32px; background: var(--bg); border-color: transparent; }
.table-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.table-list li { padding: 6px 10px; font-weight: 400; }
.table-list li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-list li .cnt { font-size: 11px; color: var(--muted); background: var(--bg); padding: 1px 7px; border-radius: 10px; }
.table-list li.active .cnt { background: var(--panel); }
.table-list .empty-note { color: var(--muted); font-size: 13px; cursor: default; }
.table-list .empty-note:hover { background: none; }
.side-footer { border-top: 1px solid var(--border-2); padding-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.side-btn {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; border: none; background: none;
  color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer; text-decoration: none; text-align: left;
}
.side-btn:hover { background: var(--bg); color: var(--text); }

.main { flex: 1; min-width: 0; overflow: auto; position: relative; }
.page { padding: 28px 32px 40px; max-width: 1680px; }
.page-head { margin-bottom: 20px; }
.mobile-menu { display: none; }

/* ---------- мониторинг ---------- */
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px 14px;
  box-shadow: var(--shadow); position: relative; overflow: hidden; min-height: 112px;
}
.card .k { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.card .v { font-size: 26px; font-weight: 700; margin: 8px 0 4px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.card .v small { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.card .d { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .spark { position: absolute; right: 14px; top: 16px; width: 38%; height: 40px; opacity: .9; }
.card .bar { height: 4px; border-radius: 4px; background: var(--border-2); margin-top: 10px; overflow: hidden; }
.card .bar > i { display: block; height: 100%; border-radius: 4px; background: var(--accent); transition: width .4s; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); flex-shrink: 0; }
.dot.ok { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dot.warn { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.dot.bad { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.c-ok { color: var(--green); } .c-warn { color: var(--amber); } .c-bad { color: var(--red); }
.live { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); margin-left: 6px; vertical-align: middle; }
.live.pulse { animation: pulse 1s ease-out; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(20, 163, 90, .6); } 100% { box-shadow: 0 0 0 8px rgba(20, 163, 90, 0); } }

.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; margin-bottom: 14px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.two-col .panel { margin-bottom: 0; }
.panel.flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; }
.target-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin: 12px 0 4px; }
.target-group:first-child { margin-top: 0; }
.target { display: grid; grid-template-columns: 12px 1fr 120px 74px 24px; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border-2); }
.target-group + .target { border-top: none; }
.target .tn { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target .th { font-size: 12px; color: var(--muted); }
.target .tm { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.target svg.spark { width: 120px; height: 28px; }
.target .icon-btn { opacity: 0; width: 24px; height: 24px; }
.target:hover .icon-btn { opacity: 1; }
.clients { width: 100%; border-collapse: collapse; font-size: 13px; }
.clients th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 0 0 6px; }
.clients td { padding: 8px 0; border-top: 1px solid var(--border-2); }
.clients td:last-child, .clients th:last-child { text-align: right; }
.you { font-size: 11px; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 1px 6px; margin-left: 6px; }
.big-chart svg { width: 100%; height: 180px; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }
.empty-box { color: var(--muted); font-size: 13px; padding: 14px 0; text-align: center; }

/* ---------- создание ---------- */
.create-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.create-card {
  text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; cursor: pointer; font: inherit; color: var(--text); display: flex; flex-direction: column; gap: 6px;
  transition: border-color .15s, box-shadow .15s, transform .15s; box-shadow: var(--shadow);
}
.create-card:hover { border-color: var(--accent); box-shadow: 0 6px 20px rgba(47, 107, 255, .12); transform: translateY(-1px); }
.create-card b { font-size: 15px; }
.create-card > span:not(.cc-icon) { color: var(--muted); font-size: 13px; }
.cc-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 6px; }
.cc-icon .i { width: 20px; height: 20px; }
.cc-icon.blue { background: var(--accent-soft); color: var(--accent); }
.cc-icon.green { background: var(--green-soft); color: var(--green); }
.cc-icon.violet { background: var(--violet-soft); color: var(--violet); }
.cc-icon.amber { background: var(--amber-soft); color: var(--amber); }
.tpl-tables { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tpl-tables i { font-style: normal; font-size: 12px; background: var(--bg); border-radius: 6px; padding: 2px 8px; color: var(--text-2); }

/* ---------- SQL ---------- */
.sql-layout { display: grid; grid-template-columns: 1fr 300px; gap: 14px; }
.sql-editor textarea {
  width: 100%; min-height: 200px; resize: vertical; font: 13px/1.55 ui-monospace, "Cascadia Code", Consolas, monospace;
  margin-bottom: 12px; background: var(--panel-2);
}
.sql-help { font-size: 13px; max-height: 300px; overflow: auto; }
.sql-help .ex { display: block; width: 100%; text-align: left; border: none; background: none; padding: 5px 8px; border-radius: 7px; cursor: pointer; color: var(--text-2); font: inherit; }
.sql-help .ex:hover { background: var(--bg); color: var(--accent); }
.sql-tables details { margin-bottom: 4px; }
.sql-tables summary { cursor: pointer; padding: 3px 0; font-weight: 500; }
.sql-tables code { display: inline-block; font-size: 12px; background: var(--bg); padding: 1px 6px; border-radius: 5px; margin: 2px; cursor: pointer; }
.sql-tables code:hover { color: var(--accent); }

/* ---------- лист (как Excel) ---------- */
.sheet-page { display: flex; flex-direction: column; height: 100vh; padding: 18px 24px 0; max-width: none; }
.sheet-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.sheet-head h1 { font-size: 22px; }
.ribbon {
  display: flex; align-items: stretch; gap: 0; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px 12px 0 0; padding: 6px; flex-wrap: wrap; row-gap: 4px;
}
.rgroup { display: flex; gap: 2px; padding: 0 6px; border-right: 1px solid var(--border-2); }
.rbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 62px; padding: 5px 6px;
  border: none; background: none; border-radius: 8px; color: var(--text-2); font: inherit; font-size: 11.5px; cursor: pointer; white-space: nowrap;
}
.rbtn .i { width: 18px; height: 18px; }
.rbtn:hover { background: var(--bg); color: var(--text); }
.rbtn:disabled { opacity: .4; cursor: default; background: none; }
.rbtn.on { background: var(--accent-soft); color: var(--accent); }
.rsearch { position: relative; }
.rsearch .i { position: absolute; left: 10px; top: 10px; width: 14px; height: 14px; color: var(--muted); }
.rsearch input { padding-left: 30px; width: 240px; height: 34px; }
.fbar { display: flex; align-items: center; background: var(--panel); border: 1px solid var(--border); border-top: none; height: 34px; }
.fref { width: 90px; border: none; border-right: 1px solid var(--border); border-radius: 0; height: 100%; text-align: center; font-weight: 600; font-size: 13px; background: var(--panel-2); }
.fref:focus { box-shadow: none; }
.fx { padding: 0 10px; color: var(--muted); font-style: italic; font-family: Georgia, serif; font-size: 15px; border-right: 1px solid var(--border-2); }
.finput { flex: 1; border: none; border-radius: 0; height: 100%; font-family: inherit; }
.finput:focus { box-shadow: inset 0 -2px 0 var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--border); border-top: none; padding: 6px 8px; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--accent); border-radius: 7px; padding: 2px 4px 2px 9px; font-size: 12px; font-weight: 500; }
.chip button { border: none; background: none; color: inherit; cursor: pointer; padding: 0 3px; font-size: 14px; line-height: 1; }

.sheet-wrap {
  flex: 1; overflow: auto; position: relative; background: var(--panel); border: 1px solid var(--border); border-top: none; outline: none;
}
.sheet-wrap.static { max-height: 60vh; border: none; }
.sheet { border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: 13px; min-width: 100%; width: max-content; }
.sheet th, .sheet td {
  height: 30px; padding: 0 8px; border-right: 1px solid var(--grid-line); border-bottom: 1px solid var(--grid-line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
}
.sheet thead th { position: sticky; top: 0; z-index: 3; background: var(--grid-head); font-weight: 600; height: 44px; padding: 0; user-select: none; vertical-align: top; }
.sheet thead th.corner { left: 0; z-index: 4; cursor: pointer; }
.sheet tbody th { position: sticky; left: 0; z-index: 2; background: var(--grid-head); color: var(--muted); font-weight: 500; text-align: center; font-size: 12px; cursor: pointer; user-select: none; padding: 0 4px; }
.sheet .h { display: flex; flex-direction: column; padding: 4px 8px 0; position: relative; cursor: pointer; height: 100%; }
.sheet .h .letter { font-size: 10px; color: var(--muted); font-weight: 500; line-height: 1.2; }
.sheet .h .nm { display: flex; align-items: center; gap: 4px; overflow: hidden; }
.sheet .h .nm b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.sheet .h .nm .i { width: 12px; height: 12px; color: var(--accent); }
.sheet .h .tp { font-size: 10px; color: var(--muted); font-weight: 400; margin-left: auto; padding-left: 4px; }
.sheet .hmenu { position: absolute; right: 2px; top: 2px; width: 20px; height: 20px; border: none; border-radius: 5px; background: none; color: var(--muted); cursor: pointer; font-size: 10px; display: none; }
.sheet th:hover .hmenu { display: block; }
.sheet .hmenu:hover { background: var(--border); color: var(--text); }
.sheet .h:hover .tp { visibility: hidden; }
.sheet .rz { position: absolute; right: -3px; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 5; }
.sheet td { cursor: cell; background: var(--panel); }
.sheet td.num { text-align: right; font-variant-numeric: tabular-nums; }
.sheet td.bool { text-align: center; }
.sheet td.in { background: var(--sel-bg); }
.sheet td.act { box-shadow: inset 0 0 0 2px var(--accent); background: var(--panel); }
.sheet td.act.in { background: var(--panel); }
.sheet th.hl { background: var(--accent-soft); color: var(--accent); }
.sheet tr.phantom td { background: var(--panel-2); }
.sheet tr.phantom th { color: var(--accent); font-size: 15px; }
.sheet tr.phantom td.act { background: var(--panel); }
.sheet td.empty-msg { color: var(--muted); text-align: center; height: 80px; cursor: default; }
.sheet td.err { color: var(--red); }
.cell-editor {
  position: absolute; z-index: 6; border: 2px solid var(--accent); border-radius: 0; padding: 0 6px; font: 13px inherit;
  font-family: inherit; box-shadow: var(--shadow-lg); background: var(--panel);
}
.cell-editor:focus { box-shadow: var(--shadow-lg); }
.statusbar {
  display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; background: var(--panel); border: 1px solid var(--border);
  border-top: none; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums;
}
.statusbar b { font-weight: 600; color: var(--text); margin-left: 3px; }
.statusbar .stat { margin-left: 12px; }
.statusbar .sep { width: 1px; height: 16px; background: var(--border); }
.statusbar select { height: 24px; padding: 0 4px; font-size: 12px; }
.sheet-tabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 6px 8px; flex-shrink: 0; }
.sheet-tabs button {
  border: 1px solid var(--border); border-top: none; background: var(--panel-2); color: var(--text-2); padding: 5px 14px;
  border-radius: 0 0 8px 8px; font: inherit; font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.sheet-tabs button.active { background: var(--panel); color: var(--green); font-weight: 600; box-shadow: inset 0 -2px 0 var(--green); }
.sheet-tabs button.add { color: var(--muted); }

/* ---------- контекстное меню ---------- */
.menu {
  position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 5px; min-width: 210px;
}
.menu button {
  display: flex; width: 100%; align-items: center; gap: 10px; border: none; background: none; padding: 7px 10px; border-radius: 7px;
  font: inherit; font-size: 13px; color: var(--text); cursor: pointer; text-align: left;
}
.menu button:hover { background: var(--bg); }
.menu button.danger { color: var(--red); }
.menu button .kbd { margin-left: auto; color: var(--muted); font-size: 11px; }
.menu hr { border: none; border-top: 1px solid var(--border-2); margin: 4px 0; }

/* ---------- диалоги ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 16px; background: var(--panel); color: var(--text); padding: 0;
  width: 520px; max-width: calc(100vw - 32px); box-shadow: var(--shadow-lg);
}
dialog.wide { width: 900px; }
dialog::backdrop { background: rgba(15, 18, 25, .38); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 0 20px; }
.dlg-head h3 { font-size: 17px; }
.dlg-body { padding: 14px 20px 4px; max-height: 70vh; overflow: auto; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.col-row { display: grid; grid-template-columns: 1fr 112px auto auto auto 28px; gap: 8px; align-items: center; margin-bottom: 6px; }
.col-row label { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.hint-box { background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; color: var(--text-2); margin-bottom: 12px; }
.hint-box code, .tokens code { background: var(--panel); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; font-size: 12px; cursor: pointer; display: inline-block; margin: 2px 1px; }
.tokens code:hover { border-color: var(--accent); color: var(--accent); }
.mini { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.mini th, .mini td { border-bottom: 1px solid var(--border-2); padding: 6px 8px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.mini th { color: var(--muted); font-weight: 500; }
.mini td.num { text-align: right; font-variant-numeric: tabular-nums; }
.mini-wrap { border: 1px solid var(--border); border-radius: 10px; overflow: auto; max-height: 300px; margin-bottom: 12px; }
.values-list { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; padding: 4px; }
.values-list label { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.values-list label:hover { background: var(--bg); }
.values-list .n { margin-left: auto; color: var(--muted); font-size: 11px; }
.pivot-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hbar { display: grid; grid-template-columns: 120px 1fr 70px; gap: 8px; align-items: center; font-size: 12px; margin-bottom: 5px; }
.hbar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar .track { height: 14px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.seg { display: inline-flex; background: var(--bg); border-radius: 9px; padding: 3px; gap: 2px; }
.seg label { padding: 4px 12px; border-radius: 7px; font-size: 13px; cursor: pointer; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--panel); box-shadow: var(--shadow); font-weight: 500; }
textarea.paste-area { width: 100%; min-height: 160px; font: 12.5px ui-monospace, Consolas, monospace; }

#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); padding: 10px 16px; border-radius: 10px;
  background: #1d2130; color: #fff; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
  max-width: 520px; font-size: 13px; z-index: 100; box-shadow: var(--shadow-lg);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--red); }

/* ---------- адаптивность ---------- */
@media (max-width: 1200px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col, .sql-layout, .pivot-layout { grid-template-columns: 1fr; }
  .rbtn span { display: none; }
  .rbtn { min-width: 36px; }
}
@media (max-width: 800px) {
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .mobile-menu { display: inline-flex; position: fixed; top: 12px; right: 12px; z-index: 30; background: var(--panel); border: 1px solid var(--border); width: 36px; height: 36px; }
  .page { padding: 20px 16px 32px; }
  .sheet-page { padding: 14px 8px 0; }
  .cards { grid-template-columns: 1fr; }
  .rsearch { width: 100%; }
  .rsearch input { width: 100%; }
  .sheet-head .row { flex-wrap: wrap; }
  .col-row { grid-template-columns: 1fr 1fr; }
  .target { grid-template-columns: 12px 1fr 64px 24px; }
  .target svg.spark { display: none; }
  .field-row { grid-template-columns: 1fr; }
}

/* ---------- пользователи и права ---------- */
body:not(.role-admin) .admin-only, body.role-viewer .edit-only { display: none !important; }
.me { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 10px 6px 2px 8px; border-top: 1px solid var(--border-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.me-info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.me-info b { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-info span { font-size: 11px; color: var(--muted); }
.role-badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 7px; }
.role-badge.admin { background: var(--violet-soft); color: var(--violet); }
.role-badge.editor { background: var(--accent-soft); color: var(--accent); }
.role-badge.viewer { background: var(--bg); color: var(--text-2); }
.role-badge.off { background: var(--red-soft); color: var(--red); }
.roles-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.roles-cards .card { min-height: 0; }
.card .d.wrap { white-space: normal; margin-top: 8px; line-height: 1.45; }
.users-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.users-table th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.users-table td { padding: 12px 16px; border-bottom: 1px solid var(--border-2); vertical-align: middle; }
.users-table tr:last-child td { border-bottom: none; }
.users-table .who { display: flex; align-items: center; gap: 10px; }
.users-table .who small { display: block; color: var(--muted); font-size: 12px; }
.users-table .acts { text-align: right; white-space: nowrap; }
.users-table tr.disabled td { opacity: .55; }
@media (max-width: 800px) {
  .roles-cards { grid-template-columns: 1fr; }
  .users-table th:nth-child(3), .users-table td:nth-child(3), .users-table th:nth-child(4), .users-table td:nth-child(4) { display: none; }
}
