:root { font-family: Inter, "Segoe UI", Arial, sans-serif; }
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line); padding: 24px 16px; display: flex; flex-direction: column; background: var(--bg-2); }
.brand-block { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.brand-block div:last-child { display: flex; flex-direction: column; line-height: 1.05; }
.brand-block strong { font-size: 17px; }
.brand-block span { color: var(--muted); font-size: 12px; margin-top: 3px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; background: var(--teal); color: var(--bg); border-radius: calc(var(--r) * .42); font-weight: 800; letter-spacing: -.04em; }
nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item { position: relative; border: 0; border-radius: calc(var(--r) * .42); background: transparent; display: grid; grid-template-columns: 28px 1fr; gap: 8px; text-align: left; align-items: center; padding: 11px 10px; cursor: pointer; font-size: 13px; transition: background .16s var(--ease), opacity .16s var(--ease); }
.nav-item > span { color: var(--muted); font-size: 10px; }
.nav-item.active { background: var(--surface-2); }
.nav-item.active::before { content: ""; position: absolute; left: 0; width: 2px; height: 20px; background: var(--teal); border-radius: 2px; }
.nav-item em { grid-column: 2; color: var(--muted); font-size: 10px; font-style: normal; margin-top: -4px; }
.nav-item.disabled { opacity: .45; cursor: default; }
.sidebar-foot { margin-top: auto; color: var(--muted); font-size: 11px; display: flex; gap: 8px; align-items: center; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--error); }
.status-dot.online { background: var(--teal); }

.workspace { min-width: 0; width: 100%; max-width: var(--max); padding: 28px 34px 60px; }
.topbar { display: flex; align-items: end; justify-content: space-between; gap: 28px; border-bottom: 1px solid var(--line); padding-bottom: 22px; margin-bottom: 22px; }
.kicker { margin: 0 0 6px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .13em; }
h1, h2 { margin: 0; letter-spacing: -.035em; }
h1 { font-size: clamp(28px, 3.2vw, 43px); font-weight: 650; }
h2 { font-size: 21px; font-weight: 620; }
.project-control { min-width: min(430px, 42vw); }
.project-control > label, label > span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 7px; }
.project-row { display: grid; grid-template-columns: minmax(180px, 1fr) auto; gap: 8px; }
select, input, textarea { width: 100%; background: var(--field); border: 1px solid var(--line-strong); color: var(--text); border-radius: calc(var(--r) * .42); padding: 10px 11px; outline: none; transition: border-color .16s var(--ease), box-shadow .16s var(--ease); }
input:focus, select:focus, textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 2px var(--teal-deep); }
textarea { resize: vertical; }
.button { border: 1px solid transparent; border-radius: calc(var(--r) * .42); padding: 9px 13px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .16s var(--ease), border-color .16s var(--ease), transform .16s var(--ease), opacity .16s var(--ease); }
.button:disabled { opacity: .5; cursor: wait; }
.button.primary { background: var(--teal); border-color: var(--teal); color: var(--bg); }
.button.primary:hover:not(:disabled) { background: var(--teal-soft); border-color: var(--teal-soft); }
.button.secondary { background: var(--surface-2); border-color: var(--line-strong); }
.button.secondary:hover:not(:disabled) { background: var(--teal-deep); border-color: var(--teal); }

.message { position: sticky; top: 12px; z-index: 15; padding: 11px 13px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: calc(var(--r) * .48); background: var(--surface-2); font-size: 12px; box-shadow: 0 8px 28px var(--shadow); }
.message.success { border-color: var(--teal); }
.message.warning { border-color: var(--teal-soft); }
.message.error { border-color: var(--error); }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.metric { min-height: 116px; background: var(--surface); border: 1px solid var(--line); border-radius: calc(var(--r) * .55); padding: 15px; display: flex; flex-direction: column; }
.metric > span { color: var(--muted); font-size: 11px; }
.metric strong { font-size: 31px; font-weight: 640; margin-top: 12px; }
.metric small { margin-top: auto; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric.attention { border-color: var(--teal-soft); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 16px; overflow: clip; }
.section-head { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.sources-list { padding: 8px; }
.source-card { min-height: 72px; display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(190px, .8fr) auto; align-items: center; gap: 18px; padding: 11px 10px; border-bottom: 1px solid var(--line); }
.source-card:last-child { border-bottom: 0; }
.source-main { min-width: 0; }
.source-title { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.source-title strong { font-size: 13px; }
.pill { border: 1px solid var(--line-strong); color: var(--muted); font-size: 9px; padding: 2px 5px; border-radius: calc(var(--r) * .28); }
.source-main code { display: block; color: var(--soft); font: 11px Consolas, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-meta { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 10px; }
.scan-state { width: fit-content; font-size: 10px; font-weight: 600; }
.scan-state.ok { color: var(--teal); }.scan-state.warn { color: var(--teal-soft); }.scan-state.bad { color: var(--error); }.scan-state.muted { color: var(--muted); }
.warning-text { color: var(--teal-soft); }
.source-form { display: grid; grid-template-columns: minmax(180px, .45fr) minmax(280px, 1.4fr) auto; align-items: end; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.form-actions { display: flex; gap: 7px; }

.structure-title-row { align-items: end; }
.scan-policy { color: var(--muted); font-size: 10px; max-width: 56%; text-align: right; }
.filters { display: grid; grid-template-columns: minmax(260px, 1.5fr) minmax(180px, .7fr) minmax(150px, .55fr); gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.filters label > span { margin-bottom: 5px; }
.filters input, .filters select { padding-block: 8px; font-size: 12px; }
.artifact-list { padding: 8px; }
.artifact-card { border-bottom: 1px solid var(--line); }
.artifact-card:last-child { border-bottom: 0; }
.artifact-card > summary { list-style: none; min-height: 62px; display: grid; grid-template-columns: 50px minmax(180px, 1.6fr) minmax(100px, .55fr) minmax(100px, .6fr) minmax(150px, .7fr) 20px; gap: 12px; align-items: center; padding: 8px 10px; cursor: pointer; border-radius: calc(var(--r) * .35); transition: background .16s var(--ease); }
.artifact-card > summary::-webkit-details-marker { display: none; }
.artifact-card > summary:hover { background: var(--surface-2); }
.discipline-badge { min-width: 42px; width: fit-content; text-align: center; border: 1px solid var(--line-strong); padding: 5px 7px; border-radius: calc(var(--r) * .35); font-size: 10px; font-weight: 700; }
.discipline-badge.unknown { color: var(--teal-soft); border-color: var(--teal-soft); }
.artifact-copy { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.artifact-copy strong { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.artifact-copy small { color: var(--muted); font: 9px Consolas, monospace; }
.artifact-kind, .formats, .availability { color: var(--muted); font-size: 10px; }
.availability.has-missing { color: var(--teal-soft); }
.chevron { color: var(--muted); transition: transform .15s var(--ease); }
.artifact-card[open] .chevron { transform: rotate(180deg); }
.representation-list { margin: 0 10px 9px 72px; border-left: 1px solid var(--line-strong); }
.representation-row { display: grid; grid-template-columns: 44px minmax(240px, 1.7fr) 90px 120px 82px; gap: 12px; align-items: center; min-height: 55px; padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: 10px; color: var(--muted); }
.representation-row:last-child { border-bottom: 0; }
.representation-row.missing { opacity: .55; }
.file-ext { font-weight: 700; color: var(--soft); }
.file-copy { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.file-copy strong { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.file-copy code { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 9px; }
.rep-status { color: var(--teal); }.representation-row.missing .rep-status { color: var(--error); }
.empty-state { min-height: 90px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; text-align: center; padding: 20px; }
.empty-state.large { min-height: 190px; flex-direction: column; gap: 8px; }.empty-state.large strong { color: var(--text); font-size: 15px; }

.onboarding { padding: 34px; min-height: 330px; display: grid; grid-template-columns: 1.1fr .9fr; gap: 44px; align-items: center; }
.onboarding-copy h2 { font-size: 30px; margin-bottom: 13px; }.onboarding-copy > p:not(.kicker) { max-width: 560px; color: var(--muted); line-height: 1.55; }.onboarding-copy .button { margin-top: 13px; }
.flow-preview { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 10px; }.flow-preview span { border: 1px solid var(--line); background: var(--surface-2); border-radius: calc(var(--r) * .35); padding: 12px; color: var(--soft); }.flow-preview b { color: var(--teal); }

dialog { width: min(560px, calc(100vw - 32px)); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: var(--r); padding: 0; box-shadow: 0 30px 90px var(--shadow-strong); }
dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
.dialog-form { padding: 22px; display: flex; flex-direction: column; gap: 15px; }.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }.icon-button { border: 0; background: transparent; font-size: 24px; color: var(--muted); cursor: pointer; }.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 5px; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 196px minmax(0, 1fr); }
  .workspace { padding-inline: 22px; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .source-card { grid-template-columns: minmax(0,1fr) auto; }.source-meta { grid-row: 2; }.scan-button { grid-row: 1 / span 2; grid-column: 2; }
  .artifact-card > summary { grid-template-columns: 46px minmax(170px,1fr) 90px 90px 20px; }.availability { display: none; }
}
@media (max-width: 760px) {
  .app-shell { display: block; }.sidebar { position: static; width: 100%; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }.sidebar nav { display: none; }.sidebar-foot { display: none; }.brand-block { padding-bottom: 0; }
  .workspace { padding: 20px 14px 44px; max-width: none; }.topbar { align-items: stretch; flex-direction: column; }.project-control { min-width: 0; }.summary-grid { grid-template-columns: 1fr 1fr; }
  .source-form, .filters { grid-template-columns: 1fr; }.source-card { grid-template-columns: 1fr; }.scan-button { grid-row: auto; grid-column: auto; width: 100%; }.scan-policy { max-width: none; text-align: left; }
  .structure-title-row { align-items: flex-start; flex-direction: column; }.artifact-card > summary { grid-template-columns: 44px minmax(0,1fr) 20px; }.artifact-kind, .formats, .availability { display: none; }.representation-list { margin-left: 22px; }.representation-row { grid-template-columns: 40px minmax(0,1fr) 76px; }.representation-row > :nth-child(4), .representation-row > :nth-child(5) { display: none; }
  .onboarding { grid-template-columns: 1fr; padding: 24px; }.flow-preview { display: none; }
}

/* Web access and administration */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: var(--bg); }
.login-card { width: min(460px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 30px; box-shadow: 0 26px 80px var(--shadow-strong); display: grid; gap: 24px; }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand > div:last-child { display: flex; flex-direction: column; line-height: 1.05; }
.login-brand strong { font-size: 18px; }
.login-brand span { color: var(--muted); font-size: 12px; margin-top: 4px; }
.login-note, .section-note, .form-note, .dialog-copy { color: var(--soft); line-height: 1.55; font-size: 13px; margin: 9px 0 0; }
.login-form { display: grid; gap: 15px; }
.wide { width: 100%; }
.setup-notice { border: 1px solid var(--teal); background: var(--teal-deep); border-radius: calc(var(--r) * .55); padding: 13px 14px; display: grid; gap: 4px; }
.setup-notice strong { font-size: 13px; }
.setup-notice span { color: var(--soft); font-size: 12px; line-height: 1.45; }

.topbar-actions { display: flex; align-items: end; gap: 14px; }
.user-menu { min-width: 230px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.user-copy { display: flex; flex-direction: column; min-width: 0; text-align: right; }
.user-copy strong { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-copy span { color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.admin-panel { min-height: 420px; }
.admin-summary { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0; }
.admin-summary span { background: var(--surface-2); border: 1px solid var(--line); border-radius: calc(var(--r) * .42); padding: 9px 11px; color: var(--muted); font-size: 11px; }
.admin-summary strong { color: var(--text); margin-right: 4px; }
.users-list { display: grid; gap: 8px; }
.user-card { display: grid; grid-template-columns: minmax(220px, 1.15fr) minmax(220px, 1fr) minmax(220px, .9fr) auto; gap: 16px; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: calc(var(--r) * .55); padding: 13px 14px; transition: border-color .16s var(--ease), opacity .16s var(--ease); }
.user-card:hover { border-color: var(--line-strong); }
.user-card.disabled-user { opacity: .62; }
.user-main { display: flex; flex-direction: column; min-width: 0; }
.user-main strong { font-size: 13px; }
.user-main span, .user-meta span { color: var(--muted); font-size: 10px; overflow: hidden; text-overflow: ellipsis; }
.user-badges { display: flex; flex-wrap: wrap; gap: 5px; }
.user-meta { display: grid; gap: 4px; }
.user-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.pill.accent { border-color: var(--teal); background: var(--teal-deep); color: var(--teal-soft); }
.checkbox-row { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.checkbox-row input { width: 16px; height: 16px; margin: 0; accent-color: var(--teal); }
.checkbox-row span { margin: 0; color: var(--soft); }

@media (max-width: 1180px) {
  .topbar { align-items: flex-start; }
  .topbar-actions { flex-direction: column; align-items: stretch; }
  .user-menu { min-width: 0; }
  .user-card { grid-template-columns: minmax(200px,1fr) minmax(180px,1fr); }
  .user-actions { justify-content: flex-start; }
}

@media (max-width: 760px) {
  .login-screen { padding: 14px; }
  .login-card { padding: 22px; }
  .topbar-actions { width: 100%; }
  .user-menu { justify-content: space-between; }
  .user-copy { text-align: left; }
  .user-card { grid-template-columns: 1fr; }
}

/* Project administration */
.admin-projects-panel { margin-top: 16px; }
.admin-projects-list { display: grid; gap: 8px; }
.admin-project-card { display: grid; grid-template-columns: minmax(220px, 1.2fr) minmax(220px, .95fr) auto; gap: 16px; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: calc(var(--r) * .55); padding: 14px; }
.admin-project-card.archived { opacity: .72; }
.admin-project-main { min-width: 0; display: grid; gap: 5px; }
.admin-project-title { display: flex; gap: 8px; align-items: center; min-width: 0; }
.admin-project-title strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-code { font: 10px Consolas, monospace; color: var(--teal-soft); border: 1px solid var(--line-strong); border-radius: calc(var(--r) * .3); padding: 4px 6px; flex: 0 0 auto; }
.admin-project-main p { color: var(--muted); font-size: 10px; line-height: 1.45; margin: 0; }
.admin-project-meta { display: flex; flex-wrap: wrap; gap: 6px; color: var(--muted); font-size: 10px; }
.admin-project-meta span { border-right: 1px solid var(--line); padding-right: 7px; }
.admin-project-meta span:last-child { border-right: 0; padding-right: 0; }
.admin-project-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.button.danger { border-color: var(--error); color: var(--text); background: transparent; }
.button.danger:hover { background: var(--error); border-color: var(--error); }
.danger-note { border: 1px solid var(--error); border-radius: calc(var(--r) * .45); padding: 11px 12px; color: var(--soft); font-size: 11px; line-height: 1.5; }
.wide-dialog { width: min(840px, calc(100vw - 32px)); }
.membership-editor { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(220px, .8fr) auto; gap: 10px; align-items: end; }
.membership-list { display: grid; gap: 7px; margin-top: 4px; max-height: 420px; overflow: auto; }
.membership-row { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(150px, .6fr) auto; gap: 12px; align-items: center; background: var(--bg-2); border: 1px solid var(--line); border-radius: calc(var(--r) * .45); padding: 11px 12px; }
.membership-row.inactive { opacity: .58; }
.membership-user { min-width: 0; display: grid; gap: 3px; }
.membership-user strong { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.membership-user span { color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.membership-role { color: var(--soft); font-size: 10px; }
.membership-actions { display: flex; gap: 6px; justify-content: flex-end; }

@media (max-width: 980px) {
  .admin-project-card { grid-template-columns: 1fr; }
  .admin-project-actions { justify-content: flex-start; }
  .membership-editor { grid-template-columns: 1fr; }
  .membership-row { grid-template-columns: 1fr; }
  .membership-actions { justify-content: flex-start; }
}

/* Локальный агент */
.section-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.source-form-v2 { grid-template-columns: minmax(170px,.75fr) minmax(190px,.85fr) minmax(210px,1fr) minmax(250px,1.25fr) auto; }
.source-agent-help { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 10px; line-height: 1.45; }
.agent-state { width: fit-content; font-size: 10px; font-weight: 650; }
.agent-state.online { color: var(--teal); }
.agent-state.offline { color: var(--error); }
.agent-pair-card { display: grid; gap: 8px; padding: 16px; border: 1px solid var(--line-strong); background: var(--bg-2); border-radius: calc(var(--r) * .5); }
.agent-pair-card > span, .agent-pair-card > small { color: var(--muted); font-size: 10px; }
.agent-pair-card > strong { font: 700 30px/1.1 Consolas, monospace; letter-spacing: .16em; color: var(--teal-soft); }
.agent-actions { justify-content: flex-start; margin-top: 0; }
.agent-devices-list { display: grid; gap: 7px; max-height: 330px; overflow: auto; }
.agent-device-row { display: grid; grid-template-columns: minmax(180px,1fr) minmax(180px,1fr) auto; gap: 12px; align-items: center; padding: 11px 12px; border: 1px solid var(--line); background: var(--bg-2); border-radius: calc(var(--r) * .45); }
.agent-device-main { min-width: 0; display: grid; gap: 4px; }
.agent-device-main strong { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-device-main span, .agent-device-meta { color: var(--muted); font-size: 10px; }
.agent-device-meta { display: grid; gap: 4px; min-width: 0; }
.agent-device-meta code { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--soft); font-size: 9px; }

@media (max-width: 1180px) {
  .source-form-v2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .source-form-v2 .form-actions { grid-column: 1 / -1; }
  .agent-device-row { grid-template-columns: 1fr auto; }
  .agent-device-meta { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .source-form-v2 { grid-template-columns: 1fr; }
  .source-form-v2 .form-actions, .source-agent-help { grid-column: auto; }
  .section-actions { justify-content: flex-start; }
  .agent-device-row { grid-template-columns: 1fr; }
}
