/* PolSim design system (stage U1.1). Component layer — tokens live in
   tokens.css (loaded first). Old component classes (.nav, .card, .grid,
   .btn/.secondary/.danger, .badge, .table, inputs, .muted/.t/.ok/.warn/
   .danger-text) are preserved: templates and the React bundles use them. */

/* 1. base */
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 400 var(--fs-base)/var(--lh-base) var(--font-ui); }
h1, h2, h3 { margin-top: 0; line-height: var(--lh-tight);
             letter-spacing: -0.01em; font-weight: 600; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px;
                 border-radius: 2px; }
.num, .metric b, td.num { font-variant-numeric: tabular-nums;
                          font-family: var(--font-mono); }
.caps { font-size: var(--fs-xs); text-transform: uppercase;
        letter-spacing: var(--ls-caps); color: var(--text-muted); }

/* 2. nav (current .nav; У1.3 adds the CSS-only Admin dropdown) */
.nav { background: var(--nav-bg); color: var(--nav-ink); padding: var(--sp-2) var(--sp-4);
       font-size: var(--fs-md); display: flex; gap: var(--sp-4); align-items: center; }
.nav a { color: var(--nav-ink); }
.nav a.brand { color: #fff; font-weight: 600; }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }
.nav form.inline { display: inline; }
.nav .nav-logout { padding: 2px var(--sp-2); margin-right: 0; display: inline-flex;
                    align-items: center; gap: 4px; }
/* details/summary CSS-only dropdown (У1.3 Б-nav): no JS, closes on outside
   click via native <details> semantics (browser default) or navigation. */
details.nav-menu { position: relative; }
details.nav-menu summary {
  cursor: pointer; list-style: none; color: var(--nav-ink);
  display: inline-flex; align-items: center; gap: 4px;
}
details.nav-menu summary::-webkit-details-marker { display: none; }
details.nav-menu summary::after {
  content: ""; width: 0; height: 0; margin-left: 2px;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid currentColor; transition: transform var(--dur-fast) var(--ease-out);
}
details.nav-menu[open] summary::after { transform: rotate(-180deg); }
.nav-menu-list {
  position: absolute; top: 100%; left: 0; margin-top: var(--sp-2);
  display: flex; flex-direction: column; min-width: 180px;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-2);
  z-index: var(--z-nav); padding: var(--sp-2) 0;
}
.nav-menu-list a {
  padding: var(--sp-2) var(--sp-3); color: var(--text); white-space: nowrap;
}
.nav-menu-list a:hover { background: var(--surface-2); text-decoration: none; }

/* 3. page header: единый header.page + .back-link + .page-actions (У1.3 —
      разметка на всех 11 страниц с header.page унифицирована в шаблонах,
      здесь только CSS-компонент). */
header.page, .page {
  padding: var(--sp-4) 128px;  /* боковые поля: h1 не наезжает на absolute back-link/page-actions */
  text-align: center;
  font-size: var(--fs-xl);
  font-weight: 600;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.back-link {
  position: absolute; left: var(--sp-4); top: 50%; transform: translateY(-50%);
  font-size: var(--fs-md); border: 1px solid var(--border);
  padding: 4px var(--sp-3); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.page h1 { margin: 0; }
.page-actions { display: flex; gap: var(--sp-2); align-items: center; }
/* dark ("sim-pages") variant — simulations/simulation/sim_map/sim_graph/
   sim_timeline shipped their own header.page{background:var(--nav-bg);...}
   with small differences; unified here as a modifier, applied in markup. */
.page--dark {
  text-align: left; font-weight: 400; font-size: var(--fs-md);
  background: var(--nav-bg); color: #fff;
  padding: var(--sp-3) var(--sp-5);
  display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center;
  position: static;
}
.page--dark a { color: var(--nav-ink); }
/* dark-variant headers are a static flex row (no header.page position:relative
   anchor) — the light .back-link's absolute positioning would escape it, so
   flatten it back into a normal flex item here (У1.3 header unification). */
.page--dark .back-link {
  position: static; transform: none; background: transparent; border: 0;
  padding: 0; color: var(--nav-ink);
}
.page--dark h1 {
  font: inherit; margin: 0; display: flex; align-items: center; gap: var(--sp-2);
}
.page--dark .page-actions { margin-left: auto; }

/* 4. cards */
.card { background: var(--surface-2); border: 1px solid var(--border);
        border-radius: var(--radius); padding: var(--sp-4); margin-bottom: var(--sp-4);
        box-shadow: var(--shadow-1); }
.card--hero {
  position: relative; isolation: isolate; background: var(--surface-2);
}
.card--hero::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none;
}

/* 5. buttons */
.btn, button {
  background: var(--primary); color: var(--primary-ink); border: 0;
  border-radius: var(--radius-sm); padding: 9px var(--sp-4); cursor: pointer;
  font: inherit; margin-right: var(--sp-2);
  transition: transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}
.btn:hover, button:hover { transform: translateY(-1px); box-shadow: var(--shadow-1); }
.btn:active, button:active { transform: translateY(0); box-shadow: none; }
.btn.secondary, button.secondary { background: var(--secondary); }
.btn.danger, button.danger { background: var(--danger); }
.btn:disabled, button:disabled {
  opacity: .5; cursor: not-allowed; transform: none; box-shadow: none;
}

/* 6. pills — one tinted component; .badge stays an alias so templates keep working */
.pill, .badge {
  display: inline-block; font-size: var(--fs-sm); padding: 2px var(--sp-2);
  border-radius: 999px; background: var(--surface-1); border: 1px solid var(--border);
  color: var(--text);
}
.pill--ok { background: color-mix(in srgb, var(--ok) 14%, var(--surface-1));
            color: var(--ok); border-color: transparent; }
.pill--warn { background: color-mix(in srgb, var(--warn) 14%, var(--surface-1));
              color: var(--warn); border-color: transparent; }
.pill--danger { background: color-mix(in srgb, var(--danger) 14%, var(--surface-1));
                color: var(--danger); border-color: transparent; }
.pill--muted { background: var(--surface-1); color: var(--text-muted); }

/* 7. tables */
table.table, table { width: 100%; border-collapse: collapse; }
.table td, .table th, table td, table th {
  text-align: left; padding: 7px var(--sp-2); border-bottom: 1px solid var(--border);
  font-size: var(--fs-base);
}
.table th, table th { color: var(--text-muted); font-weight: 600; }
.table-scroll { overflow: auto; }
.table-scroll th, .table-scroll table th { position: sticky; top: 0; background: var(--surface-1); }

/* 8. forms */
input, textarea, select {
  width: 100%; padding: var(--sp-2); background: var(--surface-1); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); box-sizing: border-box;
  font: inherit;
}
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}

/* 9. chat-modal — union of institution.html (container/.chat-close/flex header)
      and dm_profile.html (.chat-footer, which institution lacked) */
.chat-modal {
  position: fixed; top: 10%; left: 50%; transform: translateX(-50%);
  width: 500px; max-width: 90%; height: 70vh; display: none; flex-direction: column;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2); z-index: var(--z-modal);
}
.chat-modal-header {
  background: var(--surface-1); padding: 12px; border-bottom: 1px solid var(--border);
  font-weight: 700; display: flex; justify-content: space-between; align-items: center;
}
.chat-modal-body { padding: 16px; flex: 1; overflow-y: auto; font-size: var(--fs-md); }
.chat-message { margin-bottom: 16px; display: flex; align-items: flex-start; gap: 8px; max-width: 90%; }
.chat-message.user { justify-content: flex-start; }
.chat-message.agent { justify-content: flex-end; }
/* stage U (U1.2): emoji avatars (👤/🤖) replaced with initials-in-a-circle,
   generated content — no per-user data available here, so the initials are
   fixed short labels, not names. */
.chat-message.user::before, .chat-message.agent::before {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs); font-weight: 700; color: var(--primary-ink);
}
.chat-message.user::before { content: 'U'; background: var(--secondary); }
.chat-message.agent::before { content: 'AI'; background: var(--primary); font-size: 9px; }
.chat-close { cursor: pointer; font-size: 18px; }
.chat-footer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.chat-footer input { flex: 1; padding: 6px; }
.chat-footer button { padding: 6px 12px; }

/* 10. metric / stat-card — from admin_dashboard.html's local .metric.
   NOTE(v3-u): skeleton envisions a .caps-label + fs-2xl mono value; the
   actual markup shipped by admin_dashboard.html uses .v/.l, so those are
   preserved verbatim (unchanged values) to keep this step CSS-dedup-only.
   У2.2's stat-row can adopt .caps/.num directly (already defined above). */
.metric { background: var(--surface-2); border: 1px solid var(--border);
          border-radius: var(--radius); padding: var(--sp-4); }
.metric .v { font-size: 26px; font-weight: 700; }
.metric .l { color: var(--text-muted); font-size: var(--fs-base); margin-top: 4px; }

/* 11. toast (wired up in У1.4) */
.toast-host {
  position: fixed; right: var(--sp-4); bottom: var(--sp-4); z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.toast {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-4); box-shadow: var(--shadow-2); font-size: var(--fs-base);
  color: var(--text); animation: toast-in var(--dur-med) var(--ease-out);
}
.toast--ok { border-color: var(--ok); }
.toast--warn { border-color: var(--warn); }
.toast--danger { border-color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 12. skeleton (loading placeholders) */
.skeleton {
  background: linear-gradient(90deg, var(--g-3), var(--g-4), var(--g-3));
  background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* 13. icons — selector is STRICTLY svg.icon: bare .icon is already the feed
       emoji-marker class in simulation.html and must keep working */
svg.icon {
  width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px;
}
svg.icon--lg { width: 20px; height: 20px; }

/* 14. empty-state */
.empty { color: var(--text-muted); text-align: center; padding: var(--sp-6); }

/* 15. layout */
main { max-width: 1100px; margin: 0 auto; padding: var(--sp-5); }
.main--wide { max-width: 1480px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
@media (max-width: 1100px) {
  main { padding: var(--sp-4); }
}
@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr; }
}

/* dm_profile relayout (У2.1, fixes Б3): .dm-content is a normal scrolling
   document; .dm-chat is a collapsible drawer sibling (flex, NOT overlay), so
   open state shrinks the content column instead of covering it. JS toggles
   data-chat-open on .dm-layout (see dm_profile.html block scripts). */
.dm-layout { display: flex; align-items: flex-start; }
.dm-content { flex: 1 1 auto; min-width: 0; }
.dm-chat {
  flex: 0 0 auto; width: 0; overflow: hidden; margin-left: 0;
  display: flex; flex-direction: column;
  height: 640px; max-height: calc(100vh - 2 * var(--sp-5));
  position: sticky; top: var(--sp-5);
  border: 1px solid transparent; border-radius: var(--radius);
  background: var(--surface-2);
  transition: width var(--dur-med) var(--ease-out),
              margin-left var(--dur-med) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.dm-layout[data-chat-open="true"] .dm-chat {
  width: 420px; margin-left: var(--sp-5);
  border-color: var(--border); box-shadow: var(--shadow-1);
}
.dm-hero { display: flex; align-items: flex-start; gap: var(--sp-4); }
.dm-hero-photo {
  width: 96px; height: 96px; object-fit: cover; flex: none;
  border-radius: var(--radius); box-shadow: var(--shadow-1);
}
.dm-hero-info { flex: 1; min-width: 0; }
.dm-knowledge-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-5); align-items: start; }
@media (max-width: 900px) {
  .dm-layout { flex-direction: column; }
  .dm-layout[data-chat-open="true"] .dm-chat {
    width: 100%; height: 480px; max-height: none; margin-left: 0; margin-top: var(--sp-5);
    position: static;
  }
  .dm-knowledge-grid { grid-template-columns: 1fr; }
}

/* legacy aliases kept for existing inline usage across templates/React islands */
.muted { color: var(--text-muted); }
.t { color: var(--text-muted); font-size: var(--fs-sm); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.danger-text { color: var(--danger); }
