/* =============================================================================
   Kaskad WEB — дизайн-система (світла/темна тема, мобільна версія)
   ============================================================================= */
:root {
  --bg: #f5f7fb;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #e9edff 0%, rgba(233, 237, 255, 0) 60%);
  --panel: #ffffff;
  --panel-2: #f7f8fc;
  --panel-3: #eef1f8;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e4e8f0;
  --border-strong: #d3d9e6;
  --accent: #3b5bfd;
  --accent-2: #7a5cff;
  --accent-grad: linear-gradient(135deg, #3b5bfd 0%, #7a5cff 100%);
  --accent-soft: #eef1ff;
  --accent-text: #ffffff;
  --ok: #059669;
  --ok-soft: #e7f8f1;
  --warn: #b45309;
  --warn-soft: #fff5e6;
  --danger: #dc2626;
  --danger-soft: #fdeeee;
  --row-hover: #f5f7ff;
  --focus: 0 0 0 3px rgba(59, 91, 253, .18);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -6px rgba(15, 23, 42, .08);
  --shadow-lg: 0 24px 64px -12px rgba(15, 23, 42, .25);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --bg-grad: radial-gradient(1200px 600px at 100% -10%, #1a2350 0%, rgba(26, 35, 80, 0) 60%);
    --panel: #121a2e;
    --panel-2: #16203a;
    --panel-3: #1c2744;
    --text: #e8ecf6;
    --text-2: #c3cbe0;
    --muted: #8b97b5;
    --border: #243052;
    --border-strong: #2f3d66;
    --accent: #6f88ff;
    --accent-2: #9b84ff;
    --accent-grad: linear-gradient(135deg, #4f6dff 0%, #8a6dff 100%);
    --accent-soft: #1d2a55;
    --accent-text: #ffffff;
    --ok: #34d399;
    --ok-soft: #10302a;
    --warn: #fbbf24;
    --warn-soft: #33270f;
    --danger: #f87171;
    --danger-soft: #3a1c22;
    --row-hover: #18233f;
    --focus: 0 0 0 3px rgba(111, 136, 255, .28);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -10px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 64px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1 { font-size: 24px; line-height: 1.25; margin: 2px 0 4px; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 19px; margin: 0 0 6px; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 15px; margin: 0; font-weight: 600; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }

/* ---------------------------------------------------------------- controls */
.input, .field input, .field select, .field textarea {
  width: 100%;
  height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { height: auto; min-height: 96px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}
.input-search {
  padding-left: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.field .req { color: var(--danger); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.field input:disabled, .field textarea:disabled, .field select:disabled { background: var(--panel-2); color: var(--muted); }
.check { display: flex; align-items: center; gap: 9px; margin: 6px 0 14px; cursor: pointer; color: var(--text-2); }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.check-sm { font-size: 12.5px; color: var(--muted); margin: 6px 16px 4px; }
.check-inline { margin: 0; white-space: nowrap; font-size: 13px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font: inherit; font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: var(--panel-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn-primary { background: var(--accent-grad); border-color: transparent; color: var(--accent-text); box-shadow: 0 6px 16px -6px rgba(59, 91, 253, .55); }
.btn-primary:hover { background: var(--accent-grad); filter: brightness(1.06); }
.btn-danger { color: var(--danger); border-color: transparent; background: var(--danger-soft); box-shadow: none; }
.btn-danger:hover { background: var(--danger-soft); filter: brightness(.97); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--panel-3); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 44px; font-size: 15px; }
.btn-block { width: 100%; }
.icon-btn {
  border: 0; background: transparent; color: var(--text-2);
  font-size: 20px; line-height: 1; padding: 6px 9px; cursor: pointer; border-radius: 8px;
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }

.chip {
  border: 1px solid var(--border); background: var(--panel); color: var(--muted);
  padding: 4px 12px; border-radius: 999px; font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.tag {
  display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  background: var(--panel-3); color: var(--muted);
}
.tag-accent { background: var(--accent-soft); color: var(--accent); }

.error {
  background: var(--danger-soft); color: var(--danger);
  padding: 10px 14px; border-radius: var(--radius-sm); margin: 8px 0; white-space: pre-wrap; font-size: 13.5px;
}
.note {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--accent-soft); color: var(--text-2);
  padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13.5px;
}

.env-badge {
  font-size: 10.5px; font-weight: 700; letter-spacing: .6px;
  padding: 3px 8px; border-radius: 6px; background: #fde68a; color: #713f12;
}

/* ---------------------------------------------------------------- brand */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand-lg { font-size: 20px; margin-bottom: 18px; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent-grad); color: #fff; font-weight: 800; font-size: 16px;
  box-shadow: 0 6px 14px -6px rgba(59, 91, 253, .7);
}
.brand-light { color: #fff; }
.brand-light .brand-mark { background: rgba(255, 255, 255, .16); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }

/* ---------------------------------------------------------------- login */
.login { min-height: 100%; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--panel); }
.login-hero {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 48px 56px; color: #fff;
  background:
    radial-gradient(700px 400px at 0% 0%, rgba(255, 255, 255, .18), transparent 60%),
    radial-gradient(600px 500px at 100% 100%, rgba(122, 92, 255, .55), transparent 60%),
    linear-gradient(140deg, #1d2b7a 0%, #3b5bfd 55%, #7a5cff 100%);
}
.login-hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgba(255, 255, 255, .06) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(255, 255, 255, .06) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, .7), transparent 75%);
}
.hero-inner { position: relative; z-index: 1; max-width: 520px; }
.hero-title { font-size: 36px; line-height: 1.15; margin: 56px 0 16px; letter-spacing: -.03em; }
.hero-text { font-size: 16px; color: rgba(255, 255, 255, .82); max-width: 460px; }
.hero-points { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.hero-points li { display: flex; align-items: center; gap: 12px; font-size: 15px; color: rgba(255, 255, 255, .92); }
.hp-ico {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px;
  background: rgba(255, 255, 255, .16); font-size: 13px; font-weight: 700;
}
.hero-foot { position: relative; z-index: 1; font-size: 12.5px; color: rgba(255, 255, 255, .65); }
.login-side { display: grid; place-items: center; padding: 32px 24px; background: var(--bg); background-image: var(--bg-grad); }
.login-card {
  width: 100%; max-width: 400px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  padding: 36px; box-shadow: var(--shadow);
}
.login-title { font-size: 24px; margin-bottom: 4px; letter-spacing: -.02em; }
.login-card .muted { margin-bottom: 22px; }
.login-card .env-badge { display: inline-block; margin-top: 16px; }
.only-narrow { display: none; }

/* ---------------------------------------------------------------- layout */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  height: 60px; padding: 0 20px; flex-shrink: 0;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 10;
}
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 10px 4px 4px; border-radius: 999px; }
.avatar {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-grad); color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .02em;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-weight: 600; font-size: 13.5px; max-width: 28vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 11.5px; color: var(--accent); font-weight: 600; }
.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 290px; flex-shrink: 0;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.nav-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 0 10px 6px; }
.nav-title-pad { padding: 16px 20px 2px; }
.admin-nav { padding: 16px 10px 12px; border-bottom: 1px solid var(--border); }
.admin-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  color: var(--text-2); text-decoration: none; font-weight: 500;
}
.admin-link:hover { background: var(--row-hover); color: var(--text); }
.admin-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sidebar-head { display: flex; gap: 8px; padding: 8px 14px 8px; }
.kind-filter { display: flex; gap: 6px; padding: 2px 14px 4px; flex-wrap: wrap; }
.class-tree { overflow: auto; flex: 1; padding: 6px 8px 20px; }
.class-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  border: 0; background: transparent; color: var(--text-2);
  padding: 7px 10px; border-radius: 9px; font: inherit; cursor: pointer;
  position: relative;
}
.class-item:hover { background: var(--row-hover); color: var(--text); }
.class-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.class-item.active::before {
  content: ""; position: absolute; left: -8px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--accent);
}
.class-item .ico {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 8px;
  display: inline-grid; place-items: center;
  background: var(--panel-3); color: var(--muted);
}
.class-item .ico svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.class-item .ico.dictionary { background: #e6f7ef; color: #059669; }
.class-item .ico.document { background: #fff3e2; color: #d97706; }
@media (prefers-color-scheme: dark) {
  .class-item .ico.dictionary { background: #10302a; color: #34d399; }
  .class-item .ico.document { background: #33270f; color: #fbbf24; }
}
.class-item .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-empty { padding: 16px; color: var(--muted); font-size: 13px; }

.content { flex: 1; overflow: auto; padding: 28px 36px 48px; min-width: 0; background-image: var(--bg-grad); background-attachment: local; }
.empty-state { text-align: center; margin-top: 15vh; }
.empty-state-sm { margin-top: 40px; }

.class-head, .page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.class-head > div:first-child, .page-head > div:first-child { flex: 1; min-width: 220px; }
.crumbs { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.crumbs a { color: var(--muted); }
.tabs { display: inline-flex; gap: 2px; background: var(--panel-3); padding: 4px; border-radius: 12px; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 16px; border-radius: 9px; font: inherit; font-weight: 550; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .input { max-width: 360px; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; }
.props { display: grid; grid-template-columns: 200px 1fr; gap: 10px 20px; margin: 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; word-break: break-word; font-weight: 500; }

/* видимість класу для користувачів (структура, адмін) */
.class-visibility { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.vis-state { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.vis-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.vis-state.on { color: var(--ok); }
.vis-state.off { color: var(--muted); }
.class-item.is-hidden .lbl { opacity: .55; font-style: italic; }
.section-title { margin: 22px 0 10px; }

/* ---------------------------------------------------------------- dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
  position: relative; overflow: hidden;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.stat .stat-ico {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; margin-bottom: 14px;
  background: var(--accent-soft); color: var(--accent);
}
.stat .stat-ico svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stat.green .stat-ico { background: var(--ok-soft); color: var(--ok); }
.stat.amber .stat-ico { background: var(--warn-soft); color: var(--warn); }
.stat .stat-val { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat .stat-lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }
.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
.quick-list { display: grid; gap: 4px; }
.quick-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px;
  color: var(--text); text-decoration: none; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer; width: 100%;
}
.quick-item:hover { background: var(--row-hover); }
.quick-item .ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--panel-3); color: var(--muted); flex-shrink: 0; }
.quick-item .ico svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.quick-item .ico.dictionary { background: var(--ok-soft); color: var(--ok); }
.quick-item .ico.document { background: var(--warn-soft); color: var(--warn); }
.quick-item .ico.accent { background: var(--accent-soft); color: var(--accent); }
.quick-item .qi-main { display: flex; flex-direction: column; min-width: 0; }
.quick-item .qi-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quick-item .qi-sub { font-size: 12px; color: var(--muted); }
.quick-item .qi-arrow { margin-left: auto; color: var(--muted); }
.quick-empty { color: var(--muted); font-size: 13px; padding: 8px 10px; }

/* ---------------------------------------------------------------- table */
.table-wrap {
  overflow: auto; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card .table-wrap { border-radius: var(--radius-sm); box-shadow: none; }
.grid { width: 100%; border-collapse: separate; border-spacing: 0; }
.grid th, .grid td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.grid th {
  position: sticky; top: 0; z-index: 1; background: var(--panel-2);
  font-size: 11.5px; font-weight: 650; color: var(--muted); white-space: nowrap;
  text-transform: uppercase; letter-spacing: .05em;
}
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr.clickable { cursor: pointer; transition: background .1s; }
.grid tbody tr.clickable:hover { background: var(--row-hover); }
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid td.nowrap { white-space: nowrap; font-variant-numeric: tabular-nums; }
.grid td.empty { text-align: center; color: var(--muted); padding: 44px 16px; }
/* клітинка з кнопками лишається клітинкою таблиці (flex із .actions ламає рядок і межі) */
.grid td.actions { display: table-cell; white-space: nowrap; text-align: right; }
.grid td.actions > * + * { margin-left: 6px; }

/* логіка форми */
.rule-sql { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
textarea.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.panels { display: grid; gap: 10px; margin-top: 14px; }
.panel { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--panel-3); }
.panel-title { font-size: 12px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.panel-value { font-size: 22px; font-weight: 700; }
.panel-error { color: var(--danger); font-size: 13px; }
.grid-sm th, .grid-sm td { padding: 6px 10px; font-size: 13px; }

/* пейджер журналу */
#pager { display: flex; align-items: center; justify-content: flex-end; gap: 4px; flex-wrap: wrap; }
#pager .pager-info { margin-right: 6px; color: var(--muted); }
#pager .pager-size { width: auto; min-height: 30px; padding: 2px 6px; margin-right: 10px; }
#pager .pager-btn { min-width: 32px; justify-content: center; }
#pager .pager-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; opacity: 1; }
#pager .pager-gap { padding: 0 4px; color: var(--muted); }

/* колекції (табличні частини) у картці */
.coll { margin-top: 16px; }
.coll-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.coll-title { font-weight: 700; }
.coll-grid th, .coll-grid td { padding: 4px 6px; vertical-align: top; }
.coll-grid td.cell { min-width: 120px; }
.coll-grid td.cell .field { margin: 0; }
.coll-grid td.cell .field > span:first-child, .coll-grid td.cell .hint { display: none; }
.coll-grid td.cell input, .coll-grid td.cell select { min-height: 32px; padding: 5px 8px; }
.coll-grid td.cell label.check { font-size: 0; margin: 6px 0 0; }
.coll-grid td.del { width: 32px; text-align: center; }
.coll-grid tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
.coll-grid .num, .coll-grid td.num { text-align: right; }
.grid .dim { color: var(--muted); }
.state-ok, .state-off { font-size: 12.5px; font-weight: 600; }
span.state-ok, span.state-off { display: inline-flex; align-items: center; gap: 6px; }   /* клітинку таблиці не чіпаємо */
.grid td.state-ok::before, .grid td.state-off::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: middle;
}
.state-ok { color: var(--ok); }
.state-off { color: var(--danger); }
.grid td.state-ok::before { background: var(--ok); }
.grid td.state-off::before { background: var(--danger); }

.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 12px; color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------------------- dialog */
.dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 0;
  width: min(580px, calc(100vw - 32px));
  background: var(--panel); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog.wide { width: min(780px, calc(100vw - 32px)); }
.dialog[open] { animation: dlg-in .16s ease-out; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
.dialog::backdrop { background: rgba(8, 12, 28, .5); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.dialog-head h3 { font-size: 17px; letter-spacing: -.01em; }
.dialog-body { padding: 20px 22px 6px; max-height: 66vh; overflow: auto; }
.dialog > form > .error { margin: 0 22px 10px; }
.dialog-foot { display: flex; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--panel-2); border-radius: 0 0 18px 18px; }

/* поле-посилання з автокомплітом */
.lookup { position: relative; }
.lookup-list {
  position: absolute; z-index: 5; left: 0; right: 0; top: 100%; margin-top: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); max-height: 240px; overflow: auto; padding: 4px;
}
.lookup-list button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--text); padding: 8px 10px; border-radius: 7px; font: inherit; cursor: pointer;
}
.lookup-list button:hover, .lookup-list button.hl { background: var(--row-hover); }
.lookup-list .dim { padding: 8px 10px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #0f172a; color: #fff;
  padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 100;
  max-width: calc(100vw - 32px); font-weight: 500;
  animation: dlg-in .16s ease-out;
}
.toast.err { background: var(--danger); }

.only-mobile { display: none; }

/* ---------------------------------------------------------------- адміністрування */
.field-inline { display: flex; align-items: center; gap: 10px; margin: 0; }
.field-inline > span { margin: 0; white-space: nowrap; }
.field-inline select { min-width: 260px; }

.roles-layout { display: grid; grid-template-columns: 270px 1fr; gap: 20px; align-items: start; }
.roles-list { padding: 14px; }
.role-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
  border: 0; background: transparent; color: var(--text-2); text-align: left;
  padding: 9px 10px; border-radius: 9px; font: inherit; cursor: pointer;
}
.role-item:hover { background: var(--row-hover); color: var(--text); }
.role-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.roles-main { min-width: 0; }
.tabs-left { margin-bottom: 14px; }

.rights-wrap { max-height: 64vh; }
.rights-grid th, .rights-grid td { padding: 8px 10px; }
.rights-grid th.rc { text-align: center; min-width: 76px; white-space: normal; text-transform: none; letter-spacing: 0; font-size: 11.5px; }
.rights-grid td.rc { text-align: center; }
.rights-grid td.cls { position: sticky; left: 0; background: var(--panel); min-width: 220px; font-weight: 500; }
.rights-grid th.cls { left: 0; z-index: 2; }
.rights-grid tr:hover td { background: var(--row-hover); }
.rights-grid input[type=checkbox], .grid td.rc input[type=checkbox] { width: 17px; height: 17px; cursor: pointer; accent-color: var(--accent); }

.pwd-row { display: flex; gap: 8px; }
.pwd-input { position: relative; flex: 1; min-width: 0; }
.pwd-input input { width: 100%; padding-right: 42px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .02em; }
.pwd-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 30px; display: grid; place-items: center;
  border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer;
}
.pwd-eye:hover { background: var(--panel-3); color: var(--text); }
.pwd-eye:focus-visible { outline: none; box-shadow: var(--focus); }
.pwd-eye svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 800px) { .pwd-row { flex-wrap: wrap; } .pwd-input { flex-basis: 100%; } }
.roles-edit { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.roles-edit th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 6px; }
.roles-edit td { padding: 4px 6px; }
.roles-edit select, .roles-edit input {
  width: 100%; height: 36px; padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--panel); color: var(--text); font: inherit;
}
.roles-edit td.del { width: 40px; }
.roles-edit tr.expired td { opacity: .55; }

/* ---------------------------------------------------------------- mobile */
@media (max-width: 960px) {
  .login { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .only-narrow { display: inline-flex; }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .only-mobile { display: inline-block; }
  .topbar { padding: 0 12px; gap: 8px; }
  .sidebar {
    position: fixed; z-index: 20; top: 60px; bottom: 0; left: 0;
    width: min(320px, 86vw); transform: translateX(-100%); transition: transform .2s;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .content { padding: 18px 16px 32px; }
  .user-meta { display: none; }
  .props { grid-template-columns: 1fr; gap: 2px; }
  .props dd { margin-bottom: 10px; }
  .row2 { grid-template-columns: 1fr; gap: 0; }
  .toolbar .input { max-width: none; }
  .login-card { padding: 26px 22px; }
  .roles-layout { grid-template-columns: 1fr; }
  .field-inline select { min-width: 0; width: 100%; }
  .roles-edit thead { display: none; }
  .roles-edit tr { display: grid; grid-template-columns: 1fr 1fr 40px; gap: 4px; padding: 6px 0; border-bottom: 1px solid var(--border); }
  .roles-edit td:first-child { grid-column: 1 / -1; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  h1 { font-size: 21px; }
}

/* ---------------------------------------------------------------- права класу */
.rights-list { display: flex; flex-wrap: wrap; gap: 8px; }
.right-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--panel); color: var(--text-2); cursor: pointer; font-weight: 500; font-size: 13px;
}
.right-chip input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.right-chip.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.right-chip.off { opacity: .5; cursor: not-allowed; }
.right-chip .rc-hint { font-size: 11.5px; color: var(--muted); font-weight: 400; }
.rights-grid td.rc.na { color: var(--border-strong); font-weight: 600; cursor: not-allowed; }

/* ---------------------------------------------------------------- компанія (SaaS) */
.company-chip {
  display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border-radius: 999px;
  background: var(--panel-3); color: var(--text-2); font-size: 12.5px; font-weight: 600;
  max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.company-chip:empty { display: none; }
.company-badge {
  display: inline-flex; align-items: center; gap: 6px; margin-bottom: 14px;
  padding: 4px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: 12.5px; font-weight: 600;
}
@media (max-width: 800px) { .company-chip { display: none; } }
.formula-fields { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ---------------------------------------------------------------- мова */
/* вибір мови: випадаючий список з прапорами */
.lang-switch { position: relative; display: inline-flex; flex-shrink: 0; }
.lang-switch .flag { width: 20px; height: 14px; border-radius: 3px; flex-shrink: 0; box-shadow: 0 0 0 1px rgba(15, 23, 42, .12); overflow: hidden; }
.lang-current {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 9px 0 8px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--panel-3); color: var(--text); cursor: pointer;
  font: inherit; font-size: 11.5px; font-weight: 700; letter-spacing: .04em;
}
.lang-current:hover { border-color: var(--muted); }
.lang-current:focus-visible, .lang-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lang-current .chev { width: 14px; height: 14px; fill: none; stroke: var(--muted); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s; }
.lang-switch.open .lang-current .chev { transform: rotate(180deg); }
.lang-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 60; min-width: 180px; padding: 5px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 11px; box-shadow: var(--shadow-lg, 0 12px 32px rgba(15, 23, 42, .18));
}
.lang-option {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer; font: inherit; font-size: 13.5px; text-align: left;
}
.lang-option:hover { background: var(--row-hover); }
.lang-option.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.lang-option .lang-name { flex: 1; }
.lang-option .lang-short { font-size: 11px; font-weight: 700; letter-spacing: .04em; color: var(--muted); }
.login-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.login-top .company-badge { margin-bottom: 0; }

/* ---------------------------------------------------------------- не та адреса */
.nocompany { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); background-image: var(--bg-grad); }
.nocompany-card {
  width: 100%; max-width: 520px; text-align: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 28px 32px 34px; box-shadow: var(--shadow);
}
.nocompany-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; }
.nocompany-ico {
  width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 18px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.nocompany-ico svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nocompany-card h1 { font-size: 24px; margin-bottom: 8px; }
.nocompany-card .muted { margin: 0 auto 18px; max-width: 420px; }
.nocompany-example {
  display: inline-block; padding: 10px 16px; border-radius: 10px; background: var(--panel-2); border: 1px dashed var(--border-strong);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 14px; color: var(--text); word-break: break-all;
}
/* на вузькому екрані у шапці лишається лише прапор */
@media (max-width: 800px) { .topbar .lang-current .lang-code { display: none; } .topbar .lang-current { padding: 0 6px; gap: 4px; } }
