/* ============================================================
   Эгида-Соответствие — design system
   Restrained operational dashboard, Russian GovTech.
   ============================================================ */

:root {
  color-scheme: light;

  /* Brand palette (per interface brief) */
  --navy-900: #17313a;
  --navy-800: #1d3d47;
  --teal-700: #116466;
  --teal-800: #0d5052;
  --teal-100: #dff0ed;
  --blue-600: #2563eb;
  --green-700: #146c43;
  --green-100: #e3f3ea;
  --amber-600: #b7791f;
  --amber-100: #fbeed6;
  --red-700: #9b1c31;
  --red-100: #fbe4e8;

  --gray-950: #1d252c;
  --gray-700: #3c4a54;
  --gray-600: #60707d;
  --gray-400: #93a3ac;
  --gray-300: #b9c4cb;
  --gray-200: #cbd6dc;
  --gray-100: #e4ebee;
  --gray-050: #f4f7f8;
  --white: #ffffff;

  /* Semantic */
  --bg: var(--gray-050);
  --surface: var(--white);
  --surface-muted: #f8fafb;
  --text: var(--gray-950);
  --text-muted: var(--gray-600);
  --border: var(--gray-200);
  --border-strong: var(--gray-300);
  --accent: var(--teal-700);
  --accent-strong: var(--teal-800);
  --focus: var(--blue-600);

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 2px rgba(29, 37, 44, 0.06), 0 1px 3px rgba(29, 37, 44, 0.04);
  --shadow-md: 0 6px 16px rgba(29, 37, 44, 0.08);
  --shadow-lg: 0 18px 48px rgba(29, 37, 44, 0.18);

  --topbar-h: 64px;
  --sidenav-w: 232px;
  --sidenav-w-collapsed: 68px;

  --fs-page: 1.5rem;
  --fs-section: 1.25rem;
  --fs-panel: 1rem;
  --fs-body: 0.9375rem;
  --fs-meta: 0.8125rem;
  --fs-micro: 0.75rem;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "PT Root UI", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { letter-spacing: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--blue-600); }

code {
  font-family: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--gray-100);
  border-radius: 4px;
  padding: 1px 5px;
}

.hidden { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}

.muted { color: var(--text-muted); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------------------------- Inputs ---------------------------- */

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--white);
  padding: 9px 11px;
  min-height: 40px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input::placeholder, textarea::placeholder { color: var(--gray-400); }

input:hover, select:hover, textarea:hover { border-color: var(--gray-400); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

input[readonly] { background: var(--surface-muted); color: var(--text-muted); }

textarea { resize: vertical; min-height: 90px; line-height: 1.5; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2360707d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 34px;
}

.field { margin-block-end: 14px; }
.field:last-child { margin-block-end: 0; }

.field label {
  display: block;
  font-size: var(--fs-meta);
  font-weight: 600;
  color: var(--gray-700);
  margin-block-end: 5px;
}

.field-hint { margin: 5px 0 0; font-size: var(--fs-meta); color: var(--text-muted); }
.field-error { margin: 5px 0 0; font-size: var(--fs-meta); color: var(--red-700); font-weight: 600; }

.field.invalid input,
.field.invalid textarea,
.field.invalid select { border-color: var(--red-700); box-shadow: 0 0 0 3px rgba(155, 28, 49, 0.12); }

.required-mark { color: var(--red-700); margin-inline-start: 2px; }

/* ---------------------------- Buttons ---------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  min-height: 40px;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

.btn svg { width: 17px; height: 17px; flex: none; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn-secondary { background: var(--white); border-color: var(--border-strong); color: var(--gray-950); }
.btn-secondary:hover { background: var(--surface-muted); border-color: var(--gray-400); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--gray-700); }
.btn-ghost:hover { background: var(--gray-100); }

.btn-danger { background: var(--white); border-color: var(--red-700); color: var(--red-700); }
.btn-danger:hover { background: var(--red-700); color: #fff; }

.btn-block { width: 100%; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-sm { min-height: 32px; padding: 5px 11px; font-size: var(--fs-meta); }
.btn-xs { min-height: 28px; padding: 3px 9px; font-size: var(--fs-micro); }

.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--white);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-muted); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------------------------- Login ---------------------------- */

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, #e7eef0 0%, transparent 70%),
    var(--gray-050);
}

.login-card {
  width: 100%;
  max-width: 480px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px;
}

.login-brand { display: flex; align-items: center; gap: 14px; margin-block-end: 18px; }

.login-logo, .topbar-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--navy-900);
  color: #fff;
  flex: none;
}
.login-logo svg, .topbar-logo svg { width: 24px; height: 24px; }

.login-eyebrow {
  margin: 0;
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--teal-700);
  font-weight: 700;
}
.login-title { margin: 2px 0 0; font-size: 1.5rem; font-weight: 700; }
.login-lead { margin: 0 0 20px; color: var(--text-muted); }

.login-actions { display: grid; gap: 10px; margin-block-start: 20px; }
.login-foot { margin: 18px 0 0; font-size: var(--fs-meta); color: var(--gray-400); text-align: center; }

.alert {
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: var(--fs-meta);
  margin-block-end: 16px;
  border: 1px solid transparent;
}
.alert-error { background: var(--red-100); border-color: #f0c0ca; color: var(--red-700); }
.alert-ok { background: var(--green-100); border-color: #bfe2cd; color: var(--green-700); }
.alert-warn { background: var(--amber-100); border-color: #ecd6a8; color: var(--amber-600); }
.alert-info { background: #e6f0fb; border-color: #c3dbf7; color: var(--blue-600); }

/* ---------------------------- App shell ---------------------------- */

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  background: var(--navy-900);
  color: #fff;
}

.topbar-brand { display: flex; align-items: center; gap: 11px; flex: none; }
.topbar-logo { width: 38px; height: 38px; border-radius: 9px; background: rgba(255,255,255,0.08); }
.topbar-titles { line-height: 1.15; }
.topbar-product { margin: 0; font-weight: 700; font-size: 0.95rem; }
.topbar-sub { margin: 0; font-size: var(--fs-micro); color: #9fc2bd; }

.topbar-org { display: flex; align-items: center; gap: 8px; flex: none; }

.org-switcher {
  min-height: 36px;
  background-color: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 5px 30px 5px 10px;
  max-width: 240px;
  text-overflow: ellipsis;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239fc2bd' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}
.org-switcher option { color: var(--text); }

.org-badge {
  display: inline-flex; align-items: center; max-width: min(280px, 36vw);
  padding: 5px 12px; border-radius: 999px;
  background: rgba(255,255,255,0.1); color: #d8ebe8;
  border: 1px solid rgba(255,255,255,0.16);
  font-size: var(--fs-meta); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.env-badge {
  font-size: var(--fs-micro);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(183, 121, 31, 0.22);
  color: #f3d9a8;
  border: 1px solid rgba(183, 121, 31, 0.5);
}
.env-badge.env-prod { background: rgba(20, 108, 67, 0.25); color: #aee5c4; border-color: rgba(20,108,67,0.6); }

.topbar-chips {
  display: flex;
  gap: 7px;
  flex: 1 1 auto;
  overflow: hidden;
  justify-content: center;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  font-size: var(--fs-micro);
  white-space: nowrap;
  cursor: default;
}
.status-chip .chip-label { color: #9fc2bd; }
.status-chip .chip-value { color: #fff; font-weight: 600; }
.status-chip[data-clickable="true"] { cursor: pointer; }
.status-chip[data-clickable="true"]:hover { background: rgba(255,255,255,0.14); }

.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--gray-400); }
.status-dot.ok { background: #45c98a; box-shadow: 0 0 0 3px rgba(69,201,138,0.18); }
.status-dot.warn { background: #f0b955; box-shadow: 0 0 0 3px rgba(240,185,85,0.18); }
.status-dot.error { background: #ef6b7f; box-shadow: 0 0 0 3px rgba(239,107,127,0.18); }
.status-dot.neutral { background: #8aa0a8; }

.topbar-user { flex: none; position: relative; }
.topbar-user-end { margin-left: auto; }
.user-menu-trigger {
  display: flex; align-items: center; gap: 9px;
  background: transparent; border: 1px solid rgba(255,255,255,0.14);
  border-radius: var(--radius-sm); padding: 5px 9px; cursor: pointer; color: #fff;
}
.user-menu-trigger:hover { background: rgba(255,255,255,0.08); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--teal-700); color: #fff; font-weight: 700; font-size: var(--fs-meta);
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.user-name { font-size: var(--fs-meta); font-weight: 600; }
.user-role { font-size: var(--fs-micro); color: #9fc2bd; }
.chevron {
  width: 0; height: 0;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid #9fc2bd;
}

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--white);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 50;
}
.user-menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.user-menu-head p { margin: 0; font-weight: 600; color: var(--text); }
.user-menu-head p.muted { font-weight: 400; font-size: var(--fs-meta); color: var(--text-muted); }
.user-menu-item {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 0; border-radius: var(--radius-sm);
  padding: 9px 10px; cursor: pointer; font-size: var(--fs-body);
  color: var(--gray-950);
}
.user-menu-item:hover,
.user-menu-item:focus-visible {
  background: var(--gray-100);
  color: var(--gray-950);
}

/* ---------------------------- Shell body / nav ---------------------------- */

.shell-body { flex: 1 1 auto; display: grid; grid-template-columns: var(--sidenav-w) minmax(0, 1fr); }

.sidenav {
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 10px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: width 0.18s ease;
}

.sidenav-head {
  flex: none;
  padding: 2px 2px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

.sidenav-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  color: var(--gray-700);
  font-size: var(--fs-meta);
  font-weight: 600;
}
.sidenav-toggle:hover { background: var(--gray-100); color: var(--gray-950); }
.sidenav-toggle-icon { display: inline-flex; align-items: center; justify-content: center; flex: none; }
.sidenav-toggle-icon svg { width: 18px; height: 18px; }
.sidenav-toggle-label { flex: 1 1 auto; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidenav-items {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  cursor: pointer;
  color: var(--gray-700);
  font-weight: 500;
  text-align: left;
  position: relative;
}
.nav-item svg { width: 19px; height: 19px; flex: none; color: var(--gray-600); }
.nav-item:hover { background: var(--gray-100); }
.nav-item .nav-label { flex: 1 1 auto; }
.nav-item .nav-badge {
  font-size: var(--fs-micro);
  font-weight: 700;
  background: var(--gray-100);
  color: var(--gray-700);
  border-radius: 999px;
  padding: 1px 8px;
  min-width: 20px;
  text-align: center;
}
.nav-item.active {
  background: var(--teal-100);
  color: var(--accent-strong);
  font-weight: 700;
}
.nav-item.active svg { color: var(--accent); }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px; border-radius: 3px;
  background: var(--accent);
}
.nav-item.active .nav-badge { background: #c3e6df; color: var(--accent-strong); }

.nav-section-label {
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--gray-400);
  padding: 14px 11px 4px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
}

/* Collapsed sidebar (desktop) */
@media (min-width: 1081px) {
  body.sidebar-collapsed {
    --sidenav-w: var(--sidenav-w-collapsed);
  }

  body.sidebar-collapsed .sidenav-head {
    border-bottom: 0;
    margin-bottom: 0;
    padding-bottom: 0;
  }

  body.sidebar-collapsed .sidenav-toggle {
    justify-content: center;
    padding: 8px;
  }

  body.sidebar-collapsed .sidenav-toggle-label,
  body.sidebar-collapsed .nav-label,
  body.sidebar-collapsed .nav-section-label {
    display: none;
  }

  body.sidebar-collapsed .nav-item {
    position: relative;
    justify-content: center;
    padding: 10px 8px;
    gap: 0;
  }

  body.sidebar-collapsed .nav-item.active::before {
    left: 4px;
    top: 8px;
    bottom: 8px;
  }

  body.sidebar-collapsed .nav-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 8px;
    width: 8px;
    height: 8px;
    padding: 0;
    font-size: 0;
    border-radius: 50%;
    background: var(--accent);
    color: transparent;
    overflow: hidden;
  }

  body.sidebar-collapsed .nav-item.active .nav-badge {
    background: var(--accent-strong);
  }
}

/* ---------------------------- Main area ---------------------------- */

.main-area { padding: 22px clamp(16px, 2.4vw, 30px); min-width: 0; }

.view { display: none; }
.view.active { display: block; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.view-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-block-end: 18px;
}
.view-head h2 { margin: 0; font-size: var(--fs-page); font-weight: 700; }
.view-sub { margin: 4px 0 0; color: var(--text-muted); font-size: var(--fs-meta); }
.head-actions { display: flex; gap: 10px; }

/* ---------------------------- Panels ---------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-head h3 { margin: 0; font-size: var(--fs-panel); font-weight: 700; }
.panel-body { padding: 16px; }

.block-title { margin: 0 0 10px; font-size: var(--fs-meta); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--gray-600); }

.count-pill {
  font-size: var(--fs-micro);
  font-weight: 700;
  background: var(--gray-100);
  color: var(--gray-700);
  border-radius: 999px;
  padding: 2px 9px;
}

.meta-badge {
  font-size: var(--fs-micro);
  color: var(--text-muted);
  background: var(--gray-100);
  border-radius: 999px;
  padding: 3px 9px;
}

.divider { border-top: 1px solid var(--border); margin-block: 16px; }

.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-block-start: 16px; }
.form-actions.stacked { display: grid; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------------------------- Badges & chips ---------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-micro); font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.badge-neutral { background: var(--gray-100); color: var(--gray-700); }
.badge-draft { background: var(--gray-100); color: var(--gray-700); }
.badge-ready, .badge-info { background: #e6f0fb; color: var(--blue-600); }
.badge-signed, .badge-success, .badge-published { background: var(--green-100); color: var(--green-700); }
.badge-completed { background: var(--teal-100); color: var(--accent-strong); }
.badge-warn, .badge-pending { background: var(--amber-100); color: var(--amber-600); }
.badge-error, .badge-rejected { background: var(--red-100); color: var(--red-700); }
.badge-system { background: #eae6fb; color: #5b3fb0; }
.badge-user { background: var(--teal-100); color: var(--accent-strong); }

/* ---------------------------- Empty state ---------------------------- */

.empty-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 10px; padding: 28px 18px; color: var(--text-muted);
}
.empty-state .empty-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--gray-100); color: var(--gray-400);
}
.empty-state .empty-icon svg { width: 22px; height: 22px; }
.empty-state p { margin: 0; }
.empty-state .empty-title { color: var(--text); font-weight: 600; }

/* ---------------------------- Skeleton ---------------------------- */

.skeleton { background: linear-gradient(90deg, #eef2f4 25%, #e2e9ec 37%, #eef2f4 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.skeleton-row { height: 14px; margin-block: 9px; }
.skeleton-block { height: 64px; margin-block: 8px; }

/* ---------------------------- Search & filters ---------------------------- */

.search-row { position: relative; margin-bottom: 10px; }
.search-row.grow { flex: 1 1 240px; }
.search-row input { padding-left: 36px; }
.search-row + .filter-row,
.search-row + .draft-list { margin-top: 0; }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--gray-400); pointer-events: none; }
.search-icon svg { width: 17px; height: 17px; display: block; }

.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-block: 10px; }

/* ---------------------------- Documents view ---------------------------- */

.docs-grid {
  display: grid;
  gap: 16px;
  align-items: start;
}

.docs-grid-templates {
  grid-template-columns: minmax(240px, 0.9fr) minmax(360px, 1.5fr);
}

.docs-grid-drafts {
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1fr);
}


.editor-panel { min-height: 600px; }

.template-list { display: grid; gap: 8px; max-height: 560px; overflow: auto; padding-right: 2px; }

.template-card {
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  padding: 11px 12px;
  cursor: pointer;
  display: grid;
  gap: 6px;
}
.template-card:hover { border-color: var(--gray-400); background: var(--surface-muted); }
.template-card.active { border-color: var(--accent); background: var(--teal-100); box-shadow: inset 3px 0 0 var(--accent); }
.template-card .tc-title { font-weight: 600; line-height: 1.3; }
.template-card .tc-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: var(--fs-micro); color: var(--text-muted); }

.doc-fields { display: grid; gap: 0; }

.preview-wrap { margin-block-start: 18px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.preview-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: var(--surface-muted); border-bottom: 1px solid var(--border); }
.preview-label { font-size: var(--fs-micro); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--gray-600); }
.checksum { font-size: var(--fs-micro); color: var(--gray-400); font-family: "SF Mono", ui-monospace, monospace; }

.document-preview {
  --preview-line: 28px;
  margin: 0;
  min-height: 280px;
  max-height: 520px;
  overflow: auto;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--preview-line) - 1px),
    #eef2f4 calc(var(--preview-line) - 1px),
    #eef2f4 var(--preview-line)
  );
  background-attachment: local;
  padding: calc(var(--preview-line) + 2px) 26px 24px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, monospace;
  font-size: 0.85rem;
  line-height: var(--preview-line);
  color: var(--gray-950);
}
.document-preview .ph-missing {
  background: var(--amber-100);
  color: var(--amber-600);
  border-radius: 3px;
  padding: 0 3px;
  font-weight: 700;
  vertical-align: baseline;
}

.draft-list { display: grid; gap: 8px; max-height: 280px; overflow: auto; }
.draft-card {
  text-align: left; width: 100%;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--white); padding: 10px 12px; cursor: pointer; display: grid; gap: 6px;
}
.draft-card:hover { border-color: var(--gray-400); background: var(--surface-muted); }
.draft-card.active { border-color: var(--accent); background: var(--teal-100); }
.draft-card .dc-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.draft-card .dc-title { font-weight: 600; line-height: 1.3; }
.draft-card .dc-meta { font-size: var(--fs-micro); color: var(--text-muted); }

.sign-target { font-size: var(--fs-meta); margin-block-end: 12px; }
.sign-target.has-target { color: var(--text); font-weight: 600; }

.signature-summary { margin-block-start: 12px; }
.signature-summary:empty { display: none; }
.sig-card {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 12px; background: var(--surface-muted); display: grid; gap: 6px; font-size: var(--fs-meta);
}
.sig-card .sig-row { display: flex; justify-content: space-between; gap: 8px; }
.sig-card .sig-row dt { color: var(--text-muted); }
.sig-card .sig-row dd { margin: 0; font-weight: 600; text-align: right; word-break: break-all; }

.export-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------------------------- Templates view ---------------------------- */

.templates-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 0.85fr); gap: 16px; align-items: start; }

/* Template update channel */
.update-panel { margin-block-end: 16px; }
.update-panel:empty { display: none; }
.update-banner {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px 16px;
}
.update-banner.update-warn { background: var(--amber-100); border-color: #ecd6a8; }
.update-banner.update-ok { background: var(--green-100); border-color: #bfe2cd; }
.update-banner.update-error { background: var(--red-100); border-color: #f0c0ca; }
.update-banner.update-info { background: var(--surface-muted); }
.update-banner-main { display: flex; align-items: flex-start; gap: 12px; }
.update-banner-icon { flex: none; margin-top: 1px; }
.update-banner-icon svg { width: 20px; height: 20px; }
.update-warn .update-banner-icon { color: var(--amber-600); }
.update-ok .update-banner-icon { color: var(--green-700); }
.update-error .update-banner-icon { color: var(--red-700); }
.update-info .update-banner-icon { color: var(--blue-600); }
.update-banner-text { min-width: 0; }
.update-banner-title { font-weight: 600; font-size: var(--fs-body); }
.update-banner-sub { font-size: var(--fs-meta); color: var(--text-muted); margin-block-start: 2px; }
.update-banner-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-block-start: 8px; font-size: var(--fs-micro); color: var(--text-muted); }
.update-banner-meta .uc-chan { font-weight: 600; color: var(--text); }
.update-banner-main > .btn { margin-left: auto; flex: none; }
.update-list { list-style: none; margin: 12px 0 0; padding: 12px 0 0; border-top: 1px solid rgba(0,0,0,0.08); display: flex; flex-direction: column; gap: 8px; }
.update-item { display: flex; align-items: center; gap: 10px; font-size: var(--fs-meta); }
.update-tag { flex: none; font-size: var(--fs-micro); font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.update-tag.is-new { background: var(--green-100); color: var(--green-700); }
.update-tag.is-upd { background: var(--amber-100); color: var(--amber-600); }
.update-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.update-ver { flex: none; font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: var(--fs-micro); }

.variable-preview { margin-block-start: 14px; }
.variable-preview:empty { display: none; }
.var-chip-row { display: flex; flex-wrap: wrap; gap: 7px; margin-block-start: 8px; }
.var-chip { font-size: var(--fs-micro); background: var(--teal-100); color: var(--accent-strong); border-radius: 999px; padding: 3px 10px; font-weight: 600; font-family: "SF Mono", ui-monospace, monospace; }
.var-chip-inline { padding: 2px 8px; }
.var-editor { display: grid; gap: 10px; margin-block-start: 14px; }
.var-editor-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--surface-muted);
}
.var-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.var-editor-head .var-name {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: var(--fs-meta);
  font-weight: 700;
  color: var(--text);
}
.var-editor-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: stretch;
}
.var-editor-fields .field { margin: 0; }
.var-editor-fields .field label {
  display: block;
  margin-block-end: 4px;
  font-size: var(--fs-micro);
  font-weight: 600;
  color: var(--text-muted);
}
.var-editor-fields input,
.var-editor-fields select {
  width: 100%;
  min-height: 36px;
}
.var-field-type select { min-width: 0; }
.var-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding-block: 2px;
  font-size: var(--fs-meta);
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.var-toggle input {
  width: 16px;
  height: 16px;
  min-height: auto;
  margin: 0;
  flex: none;
}

/* ---------------------------- Data tables ---------------------------- */

.data-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-meta); }
.data-table thead th {
  position: sticky; top: 0;
  background: var(--surface-muted);
  text-align: left;
  font-weight: 700;
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-600);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody td { padding: 11px 14px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--surface-muted); }
.data-table .cell-strong { font-weight: 600; color: var(--text); }
.data-table .cell-mono { font-family: "SF Mono", ui-monospace, monospace; font-size: var(--fs-micro); color: var(--text-muted); }
.data-table .cell-actions { text-align: right; white-space: nowrap; }
.table-empty { padding: 26px; }

/* Templates catalog: fit without horizontal scroll, only the title wraps */
.templates-table { table-layout: fixed; width: 100%; }
.templates-table th, .templates-table td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.templates-table th:first-child, .templates-table td:first-child { white-space: normal; overflow: visible; }
.templates-table thead th { letter-spacing: 0; }
.templates-table th:nth-child(1) { width: 32%; }
.templates-table th:nth-child(2) { width: 11%; }
.templates-table th:nth-child(3) { width: 15%; }
.templates-table th:nth-child(4) { width: 15%; }
.templates-table th:nth-child(5) { width: 11%; }
.templates-table th:nth-child(6) { width: 16%; }

/* ---------------------------- Overview ---------------------------- */

.overview-body { display: grid; gap: 16px; }
.overview-row { display: grid; gap: 16px; }
.overview-row.cols-2 { grid-template-columns: 1.3fr 1fr; align-items: start; }

.contour-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.contour-card {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--white);
  padding: 14px; display: grid; gap: 8px; box-shadow: var(--shadow-sm);
}
.contour-card .cc-head { display: flex; align-items: center; gap: 8px; }
.contour-card .cc-icon { color: var(--gray-500, var(--gray-600)); }
.contour-card .cc-icon svg { width: 18px; height: 18px; }
.contour-card .cc-name { font-size: var(--fs-meta); color: var(--text-muted); font-weight: 600; }
.contour-card .cc-value { font-size: 1.05rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.contour-card .cc-detail { font-size: var(--fs-micro); color: var(--text-muted); }

.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.quick-action {
  display: flex; align-items: center; gap: 11px; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--white);
  padding: 13px 14px; cursor: pointer;
}
.quick-action:hover { border-color: var(--accent); background: var(--teal-100); }
.quick-action .qa-icon { width: 34px; height: 34px; border-radius: 8px; background: var(--teal-100); color: var(--accent); display: grid; place-items: center; flex: none; }
.quick-action:hover .qa-icon { background: #fff; }
.quick-action .qa-icon svg { width: 18px; height: 18px; }
.quick-action .qa-label { display: block; font-weight: 600; line-height: 1.25; }
.quick-action .qa-sub { display: block; font-size: var(--fs-micro); color: var(--text-muted); margin-top: 2px; }

.attention-list { display: grid; gap: 8px; }
.attention-item {
  display: flex; gap: 11px; align-items: flex-start;
  border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius-sm);
  padding: 11px 12px; background: var(--white);
}
.attention-item.warn { border-left-color: var(--amber-600); }
.attention-item.error { border-left-color: var(--red-700); }
.attention-item.info { border-left-color: var(--blue-600); }
.attention-item .at-icon { flex: none; margin-top: 1px; }
.attention-item.warn .at-icon { color: var(--amber-600); }
.attention-item.error .at-icon { color: var(--red-700); }
.attention-item.info .at-icon { color: var(--blue-600); }
.attention-item .at-icon svg { width: 18px; height: 18px; }
.attention-item .at-title { font-weight: 600; font-size: var(--fs-meta); }
.attention-item .at-sub { font-size: var(--fs-micro); color: var(--text-muted); }
.attention-item button { margin-left: auto; }

.mini-audit { display: grid; gap: 2px; }
.mini-audit-item { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 9px 2px; border-bottom: 1px solid var(--gray-100); font-size: var(--fs-meta); }
.mini-audit-item:last-child { border-bottom: 0; }
.mini-audit-item time { font-size: var(--fs-micro); color: var(--text-muted); white-space: nowrap; }
.mini-audit-item .ma-summary { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------- Signature view ---------------------------- */

.signature-body { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.signature-body .span-2 { grid-column: 1 / -1; }

.kv-list { display: grid; gap: 0; margin: 0; }
.kv-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--gray-100); }
.kv-list > div:last-child { border-bottom: 0; }
.kv-list dt { color: var(--text-muted); font-size: var(--fs-meta); }
.kv-list dd { margin: 0; font-weight: 600; text-align: right; word-break: break-word; font-size: var(--fs-meta); }
.kv-list dd.mono { font-family: "SF Mono", ui-monospace, monospace; font-size: var(--fs-micro); }

.cert-list { display: grid; gap: 10px; }
.cert-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 13px; }
.cert-card .cert-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-block-end: 8px; }
.cert-card .cert-subject { font-weight: 600; }

.sign-result { margin-block-start: 12px; }
.sign-result pre { background: var(--gray-950); color: #d9f0ec; padding: 12px; border-radius: var(--radius-sm); overflow: auto; font-size: var(--fs-micro); max-height: 160px; margin: 8px 0 0; }

/* ---------------------------- Training view ---------------------------- */

.training-grid { display: grid; grid-template-columns: minmax(260px, 0.85fr) minmax(320px, 1.1fr) minmax(320px, 1.1fr); gap: 16px; align-items: start; }

.course-list { display: grid; gap: 12px; }
.course-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 9px; }
.course-card .course-title { font-weight: 600; }
.course-card .course-meta { font-size: var(--fs-micro); color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.progress-track { height: 8px; border-radius: 999px; background: var(--gray-100); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s ease; }
.progress-fill.full { background: var(--green-700); }
.course-card .course-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.course-card .progress-label { font-size: var(--fs-micro); font-weight: 700; color: var(--text-muted); }
.course-actions { display: flex; gap: 8px; }

.course-detail { display: grid; gap: 12px; }
.course-detail-meta { font-size: var(--fs-meta); color: var(--text-muted); }
.module-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; }
.module-item h4 { margin: 0 0 4px; font-size: var(--fs-body); }
.module-desc { font-size: var(--fs-micro); color: var(--text-muted); margin: 0 0 8px; }
.lecture-list { display: grid; gap: 6px; }
.lecture-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--gray-100); }
.lecture-row:first-child { border-top: 0; }
.lecture-row .lec-title { flex: 1 1 auto; min-width: 0; }
.lecture-row .lec-icon { flex: none; }
.lecture-row .lec-icon.done { color: var(--green-700); }
.lecture-row .lec-icon.todo { color: var(--gray-400); }
.lecture-row .lec-icon svg { width: 18px; height: 18px; display: block; }
.quiz-list { display: grid; gap: 6px; margin-block-start: 8px; }
.quiz-row { display: flex; justify-content: space-between; gap: 8px; font-size: var(--fs-meta); padding: 6px 0; border-top: 1px dashed var(--gray-200); }

/* ---------------------------- Audit view ---------------------------- */

.audit-filters { display: flex; flex-wrap: wrap; gap: 10px; margin-block-end: 14px; align-items: center; }
.audit-filters select { max-width: 200px; }

/* ---------------------------- Admin view ---------------------------- */

.admin-body { display: grid; gap: 16px; }
.admin-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--white); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.stat-card .stat-label { font-size: var(--fs-meta); color: var(--text-muted); }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; margin-block-start: 4px; line-height: 1.2; }
.stat-card .stat-value.sm { font-size: 1.0625rem; line-height: 1.35; word-break: break-word; }
.role-tags { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.role-tag { font-size: var(--fs-micro); background: var(--gray-100); color: var(--gray-700); border-radius: 4px; padding: 1px 7px; }

/* ---------------------------- Diagnostics view ---------------------------- */

.diagnostics-body { display: grid; gap: 14px; }
.diag-group { }
.diag-group .panel-head .diag-summary { font-size: var(--fs-micro); }
.diag-row { display: grid; grid-template-columns: 22px minmax(160px, 1fr) minmax(0, 1.5fr) auto; gap: 12px; align-items: start; padding: 12px 16px; border-bottom: 1px solid var(--gray-100); }
.diag-row:last-child { border-bottom: 0; }
.diag-row .diag-icon { margin-top: 1px; }
.diag-row .diag-icon svg { width: 18px; height: 18px; display: block; }
.diag-row .diag-icon.ok { color: var(--green-700); }
.diag-row .diag-icon.warn { color: var(--amber-600); }
.diag-row .diag-icon.error { color: var(--red-700); }
.diag-row .diag-icon.pending { color: var(--gray-400); }
.diag-name { font-weight: 600; }
.diag-detail { font-size: var(--fs-meta); color: var(--text); }
.diag-resolution { font-size: var(--fs-micro); color: var(--text-muted); margin-block-start: 4px; }

/* ---------------------------- Settings view ---------------------------- */

.settings-body, .profile-body { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.perm-list { margin: 0; padding-left: 1.2rem; color: var(--text); }
.perm-list li + li { margin-top: 6px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--gray-100); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .setting-label { font-weight: 600; }
.setting-row .setting-desc { font-size: var(--fs-micro); color: var(--text-muted); }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button { border: 0; background: var(--white); padding: 7px 14px; cursor: pointer; font-size: var(--fs-meta); font-weight: 600; color: var(--gray-700); }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active { background: var(--teal-100); color: var(--accent-strong); }

/* ---------------------------- Overlays: modal + drawer ---------------------------- */

.overlay-root {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(23, 49, 58, 0.45);
  display: flex;
}
.overlay-root { align-items: center; justify-content: center; padding: 24px; }
.drawer-overlay { align-items: stretch; justify-content: flex-end; padding: 0; }

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
  animation: modalIn 0.18s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.99); } to { opacity: 1; transform: none; } }

.drawer {
  background: var(--white);
  box-shadow: var(--shadow-lg);
  width: min(520px, 100%);
  height: 100%;
  overflow: auto;
  animation: drawerIn 0.2s ease;
  display: flex; flex-direction: column;
}
@keyframes drawerIn { from { transform: translateX(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }

.overlay-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--white); z-index: 1;
}
.overlay-head h3 { margin: 0; font-size: var(--fs-section); font-weight: 700; }
.overlay-head .overlay-sub { margin: 2px 0 0; font-size: var(--fs-meta); color: var(--text-muted); }
.overlay-close { width: 34px; height: 34px; border: 0; background: transparent; border-radius: var(--radius-sm); cursor: pointer; color: var(--gray-600); display: grid; place-items: center; }
.overlay-close:hover { background: var(--gray-100); }
.overlay-close svg { width: 18px; height: 18px; }
.overlay-body { padding: 20px; }
.overlay-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--white); }

.modal-template-editor {
  max-width: min(980px, 96vw);
}

.template-editor-layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
}

.template-editor-meta.stack-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.template-editor-content {
  display: flex;
  flex-direction: column;
  min-height: 360px;
  margin: 0;
}

.template-editor-content textarea {
  flex: 1;
  min-height: 320px;
  resize: vertical;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 13px;
  line-height: 1.55;
}

.stack-form .field,
.template-editor-form .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: var(--fs-meta);
  font-weight: 600;
  color: var(--text-muted);
}

.status-light-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}

.status-light {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-light-green {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.22);
}

.status-light-yellow {
  background: #eab308;
  box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.22);
}

.status-light-red {
  background: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.22);
}

.status-light-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-light-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.status-light-btn.is-active {
  opacity: 1;
  border-color: var(--gray-400);
  background: var(--gray-50);
}

.status-light-btn:disabled {
  cursor: not-allowed;
}

.status-light-caption {
  font-size: var(--fs-meta);
  color: var(--text-muted);
}

@media (max-width: 820px) {
  .template-editor-layout {
    grid-template-columns: 1fr;
  }

  .template-editor-content {
    min-height: 240px;
  }
}

/* tabs (drawer) */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 20px; position: sticky; top: 66px; background: var(--white); z-index: 1; }
.tab { border: 0; background: transparent; padding: 11px 12px; cursor: pointer; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; font-size: var(--fs-meta); }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-strong); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.audit-timeline { display: grid; gap: 0; }
.timeline-item { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--gray-100); }
.timeline-item:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline-item::before { content: ""; position: absolute; left: -6px; top: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--white); }
.timeline-item time { font-size: var(--fs-micro); color: var(--text-muted); }
.timeline-item .tl-summary { font-size: var(--fs-meta); font-weight: 600; }

/* ---------------------------- Toasts ---------------------------- */

.toast-region {
  position: fixed; top: 16px; right: 16px; z-index: 200;
  display: grid; gap: 10px; width: min(360px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--white); border: 1px solid var(--border); border-left-width: 4px;
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 12px 14px;
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast.toast-ok { border-left-color: var(--green-700); }
.toast.toast-error { border-left-color: var(--red-700); }
.toast.toast-warn { border-left-color: var(--amber-600); }
.toast.toast-info { border-left-color: var(--blue-600); }
.toast .toast-icon { flex: none; margin-top: 1px; }
.toast .toast-icon svg { width: 18px; height: 18px; }
.toast.toast-ok .toast-icon { color: var(--green-700); }
.toast.toast-error .toast-icon { color: var(--red-700); }
.toast.toast-warn .toast-icon { color: var(--amber-600); }
.toast.toast-info .toast-icon { color: var(--blue-600); }
.toast .toast-body { flex: 1 1 auto; min-width: 0; }
.toast .toast-title { font-weight: 600; font-size: var(--fs-meta); }
.toast .toast-text { font-size: var(--fs-micro); color: var(--text-muted); margin-top: 1px; }
.toast .toast-close { border: 0; background: transparent; cursor: pointer; color: var(--gray-400); padding: 0; }
.toast .toast-close svg { width: 16px; height: 16px; }

/* ---------------------------- Density (compact) ---------------------------- */

body.density-compact { --fs-body: 0.875rem; }
body.density-compact .panel-body { padding: 12px; }
body.density-compact .data-table tbody td { padding: 8px 12px; }
body.density-compact .btn { min-height: 36px; }

/* ---------------------------- Responsive ---------------------------- */

.mobile-nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  flex: none;
}
.mobile-nav-toggle svg { width: 20px; height: 20px; }

.sidenav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(15, 23, 42, 0.45);
}

@media (max-width: 1320px) {
  .docs-grid { grid-template-columns: minmax(220px, 0.9fr) minmax(0, 1.6fr); }
  .docs-grid > .panel:last-child { grid-column: 1 / -1; }
  .contour-grid { grid-template-columns: repeat(3, 1fr); }
  .training-grid { grid-template-columns: 1fr 1fr; }
  .training-grid > .panel:first-child { grid-column: 1 / -1; }
}

@media (max-width: 1080px) {
  .mobile-nav-toggle { display: inline-flex; }
  .shell-body { grid-template-columns: 1fr; }
  .sidenav-head { display: none; }
  .sidenav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(288px, 88vw);
    height: 100dvh;
    z-index: 60;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    flex-direction: column;
    flex-wrap: nowrap;
    overflow-x: hidden;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    border-bottom: 0;
    padding: 12px 10px 16px;
    box-shadow: var(--shadow-lg);
  }
  body.mobile-nav-open .sidenav { transform: translateX(0); }
  body.mobile-nav-open .sidenav-backdrop { display: block; }
  body.mobile-nav-open { overflow: hidden; }
  .sidenav-items {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 3px;
    width: 100%;
  }
  .nav-item { width: 100%; }
  .nav-section-label { display: block; }
  .docs-grid, .templates-grid, .training-grid, .signature-body, .settings-body, .profile-body, .overview-row.cols-2 { grid-template-columns: 1fr; }
  .docs-grid > .panel:last-child, .training-grid > .panel:first-child { grid-column: auto; }
  .contour-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 12px; gap: 10px; }
  .topbar-chips { order: 5; width: 100%; justify-content: flex-start; flex-wrap: wrap; overflow: visible; }
  .topbar-org { display: none; }
  .user-meta { display: none; }
  .form-grid, .filter-row, .admin-summary { grid-template-columns: 1fr; }
  .contour-grid { grid-template-columns: 1fr; }
  .view-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .head-actions { flex-wrap: wrap; width: 100%; }
  .diag-row { grid-template-columns: 22px 1fr; }
  .diag-row .diag-actions { grid-column: 1 / -1; }
  .drawer { width: 100%; }
  .field-inline { min-width: 0; width: 100%; }
  .table-actions { white-space: normal; }
  .toolbar-row { align-items: stretch; }
  .setting-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .overlay-root { padding: 12px; }
  .segmented { flex-wrap: wrap; max-width: 100%; }
  .editor-panel { min-height: 0; }
  .preview-head { flex-wrap: wrap; gap: 6px; }
  .checksum { word-break: break-all; }
  .data-table-wrap { -webkit-overflow-scrolling: touch; }
  .main-area { padding: 16px 12px; }
  .admin-org-picker { max-width: none; }
}

@media (max-width: 480px) {
  .login-screen { padding: 16px; }
  .login-card { padding: 20px 16px; }
  .login-brand { flex-direction: column; align-items: flex-start; gap: 12px; }
  .topbar-titles .topbar-sub { display: none; }
  .mobile-nav-toggle { width: 36px; height: 36px; }
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.field-inline {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 240px;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  white-space: nowrap;
}

.role-picker {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.role-picker .check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.admin-org-picker {
  max-width: 420px;
  margin-bottom: 16px;
}

.btn.danger {
  color: var(--danger);
}

body.documents-only .main-area-full {
  flex: 1 1 auto;
}

.download-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted, #f8fafc);
}

.download-card h4 {
  margin: 0;
  font-size: 1rem;
}

.download-card + .download-card {
  margin-top: 12px;
}
