* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, Helvetica, sans-serif;
}

body {
    background: #f1f5f9;
    color: #1e293b;
}

header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: #1e40af;
    color: white;
    padding: 18px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
}

header h2 {
    font-size: 24px;
}

nav {
    display: flex;
    gap: 15px;
    align-items: center;
}

nav a {
    color: white;
    text-decoration: none;
    font-weight: bold;
    transition: 0.2s;
    padding: 6px 10px;
    border-radius: 6px;
}

nav a:hover {
    opacity: 0.9;
    background: rgba(255, 255, 255, 0.12);
}

nav a.nav-active,
.user-menu-dropdown a.nav-active {
    background: rgba(255, 255, 255, 0.22);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.user-menu-dropdown a.nav-active {
    color: #1e40af;
    background: #dbeafe;
    box-shadow: none;
}

.user-menu {
    position: relative;
    margin-left: 8px;
}

.user-menu-toggle {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: white;
    font-weight: 700;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}

.user-menu-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 200px;
    background: white;
    color: #1e293b;
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.2);
    padding: 8px;
    z-index: 1200;
}

.user-menu-dropdown a {
    display: block;
    color: #1e293b;
    font-weight: 600;
    padding: 10px 12px;
    border-radius: 8px;
    text-decoration: none;
}

.user-menu-user {
    display: block;
    color: #64748b;
    font-weight: 700;
    padding: 10px 12px 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid #e2e8f0;
    pointer-events: none;
    user-select: text;
    cursor: default;
}

.user-menu-dropdown a:hover {
    background: #eff6ff;
    opacity: 1;
}

.page-back:empty {
    display: none;
}

.page-back {
    margin-bottom: 14px;
}

.flash {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.flash-text {
    flex: 1;
}

.flash-close {
    border: none;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    padding: 0 4px;
}

.flash-close:hover {
    opacity: 1;
}

.flash-hiding {
    opacity: 0;
    transition: opacity 0.4s ease;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.col-filter-label:focus-visible,
.user-menu-toggle:focus-visible {
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}

nav a:focus-visible,
.user-menu-toggle:focus-visible {
    outline-color: #fde68a;
}

.system-link {
    color: #1d4ed8;
    font-weight: 600;
    text-decoration: none;
}

.system-link:hover {
    text-decoration: underline;
}

.filters-on-badge {
    display: inline-block;
    margin-left: 10px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #fef3c7;
    color: #92400e;
    font-size: 12px;
    font-weight: 600;
    vertical-align: middle;
}

button[data-clear-filters-for] {
    margin-left: 8px;
    vertical-align: middle;
}

.btn-action {
    min-width: 120px;
    text-align: center;
    justify-content: center;
}

.floating-hscroll {
    position: fixed;
    left: 0;
    right: auto;
    bottom: 0;
    width: 100%;
    height: 16px;
    overflow-x: auto;
    overflow-y: hidden;
    background: rgba(226, 232, 240, 0.98);
    border-top: 1px solid #94a3b8;
    z-index: 4000;
    box-sizing: border-box;
}

.floating-hscroll[hidden] {
    display: none !important;
}

.floating-hscroll-inner {
    height: 1px;
    min-height: 1px;
    pointer-events: none;
}

.graph-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.graph-controls {
    order: -1;
    position: sticky;
    top: 0;
    z-index: 5;
    background: #f8fafc;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.graph-scroll-wrap {
    overflow: hidden;
    /* Высота окна под схему: почти весь экран минус шапка и панели */
    height: calc(100vh - 250px);
    min-height: 560px;
    max-height: none;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    box-sizing: border-box;
}

.graph-scroll-wrap .graph-canvas {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 100%;
    max-width: 100%;
}

.vis-network .vis-navigation {
    display: none !important;
}

.graph-view-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.graph-view-tools .btn-small {
    min-width: 36px;
    font-weight: 600;
    line-height: 1.2;
}

.graph-btn-fit {
    font-size: 1.05rem;
    line-height: 1;
    padding: 6px 10px;
}

.graph-canvas-interactive {
    cursor: grab;
}

.graph-canvas-interactive.is-panning {
    cursor: grabbing;
}

.attachment-list {
    list-style: none;
    padding: 0;
    margin: 12px 0;
}

.attachment-list li {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
}

.attachment-upload {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 10px;
}

.container {
    width: 95%;
    max-width: 1400px;
    margin: 30px auto;
}

.card {
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
}

.btn {
    display: inline-block;
    background: #2563eb;
    color: white;
    text-decoration: none;
    padding: 10px 18px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: 0.2s;
    font-size: 14px;
}

.btn:hover {
    background: #1d4ed8;
}

.btn-red {
    background: #dc2626;
}

.btn-red:hover {
    background: #b91c1c;
}

.btn-green {
    background: #059669;
}

.btn-green:hover {
    background: #047857;
}

.field-locked {
    background: #f1f5f9 !important;
    color: #64748b !important;
    cursor: not-allowed;
    pointer-events: none;
    border-color: #e2e8f0 !important;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background: white;
}

table th {
    background: #1e40af;
    color: white;
    padding: 12px;
    border: 1px solid #ddd;
    text-align: left;
}

table td {
    padding: 10px;
    border: 1px solid #ddd;
    vertical-align: top;
}

table tr:nth-child(even) {
    background: #f8fafc;
}

input,
textarea,
select {
    width: 100%;
    padding: 10px;
    margin-top: 5px;
    margin-bottom: 15px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
}

label {
    font-weight: bold;
}

.flash {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 6px;
    border-left: 5px solid #2563eb;
}

.flash-success {
    background: #dcfce7;
    color: #166534;
    border-left-color: #059669;
}

.flash-error {
    background: #fee2e2;
    color: #991b1b;
    border-left-color: #dc2626;
}

.flash-info {
    background: #dbeafe;
    color: #1e3a8a;
    border-left-color: #2563eb;
}

.footer {
    margin-top: 40px;
    text-align: center;
    color: #64748b;
    padding: 20px;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
    gap: 10px;
}

.toolbar-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.search-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.search-form input[type="text"] {
    max-width: 350px;
    margin: 0;
}

.pagination {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
    margin-top: 20px;
}

.pagination-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.pagination-info {
    color: #64748b;
}

.pagination-ellipsis {
    color: #94a3b8;
    padding: 0 4px;
}

.page-current {
    background: #1e40af;
    pointer-events: none;
}

.help-toc {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin-bottom: 28px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e2e8f0;
}

.help-toc a {
    color: #1e40af;
    text-decoration: none;
    font-weight: 600;
}

.help-toc a:visited {
    color: #1e40af;
}

.help-toc a:hover {
    color: #1d4ed8;
    text-decoration: none;
}

.help-section a,
.help-map a {
    color: #1e40af;
    text-decoration: none;
}

.help-section a:visited,
.help-map a:visited {
    color: #1e40af;
}

.help-section a:hover,
.help-map a:hover {
    color: #1d4ed8;
    text-decoration: none;
}

.help-section {
    margin-bottom: 28px;
    max-width: 820px;
}

.help-section h2 {
    margin: 0 0 12px;
    font-size: 1.25rem;
}

.help-section h3 {
    margin: 18px 0 8px;
    font-size: 1.05rem;
}

.help-section ol,
.help-section ul {
    margin: 0 0 10px;
    padding-left: 22px;
}

.help-section li {
    margin-bottom: 6px;
    line-height: 1.45;
}

.help-map {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
    margin-top: 10px;
}

.help-map th,
.help-map td {
    border: 1px solid #e2e8f0;
    padding: 8px 10px;
    text-align: left;
    vertical-align: top;
}

.help-map th {
    background: #1e40af;
    color: #fff;
    font-weight: 600;
}

.help-faq dt {
    font-weight: 600;
    margin-top: 14px;
}

.help-faq dd {
    margin: 4px 0 0;
    color: #334155;
}

.select-header {
    min-width: 120px;
    white-space: nowrap;
    text-align: left;
    vertical-align: middle;
}

.select-cell {
    width: 42px;
    text-align: center;
    vertical-align: middle;
}

.select-all-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
    margin: 0;
    user-select: none;
}

.select-header input,
.select-cell input {
    width: 16px;
    height: 16px;
    margin: 0;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    margin-bottom: 15px;
    color: #64748b;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(0, 0, 0, 0.12);
}

.legend-current {
    background: #1e40af;
}

.legend-source {
    background: #059669;
}

.legend-target {
    background: #d97706;
}

.legend-both {
    background: #7c3aed;
}

.graph-hint {
    margin: -4px 0 12px;
}

.graph-panel {
    margin-bottom: 35px;
}

.graph-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 14px 24px;
    align-items: center;
    margin-bottom: 12px;
}

.graph-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.graph-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 14px 18px;
}

.graph-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    color: #334155;
    font-size: 0.95rem;
}

.graph-toggle input {
    width: 16px;
    height: 16px;
    accent-color: #1e40af;
}

.graph-count {
    color: #64748b;
    font-size: 0.85rem;
}

.graph-count::before {
    content: "(";
}

.graph-count::after {
    content: ")";
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.9rem;
}

.role-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.role-form select {
    margin: 0;
    width: auto;
    min-width: 110px;
}

.badge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #e2e8f0;
    color: #334155;
    font-size: 12px;
}

.role-admin {
    color: #1d4ed8;
    font-weight: bold;
}

.role-user {
    color: #475569;
}

.add-column-form {
    max-width: 480px;
    margin-top: 10px;
}

.add-column-form input[type="text"] {
    margin-bottom: 12px;
}

.inline-form {
    display: inline;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
}

.graph-box {
    background: white;
    border: 1px solid #dbe4ee;
    border-radius: 10px;
    padding: 8px;
    overflow: hidden;
    min-height: 520px;
    position: relative;
    box-sizing: border-box;
}

.graph-box.graph-scroll-wrap {
    min-height: 560px;
}

.graph-canvas {
    width: 100%;
    min-height: 520px;
    background: #f8fafc;
    border-radius: 8px;
}

.graph-empty {
    margin: 0;
    padding: 40px 16px;
}

.graph-box iframe,
.graph-box .card {
    max-width: 100%;
}

.warning-box {
    margin-top: 30px;
    padding: 20px;
    background: #fef3c7;
    border-left: 5px solid #f59e0b;
    border-radius: 8px;
}

.empty-state {
    margin-top: 30px;
    text-align: center;
    color: #64748b;
}

.error-page {
    text-align: center;
    padding: 40px 20px;
}

.error-page h1 {
    font-size: 72px;
    color: #1e40af;
    margin-bottom: 10px;
}

.actions-column {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.hint {
    color: #64748b;
    font-size: 13px;
    margin-top: 8px;
}

.column-selector {
    margin-bottom: 20px;
    padding: 15px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
}

.column-selector-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.column-selector-grid label {
    font-weight: normal;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.column-selector-grid input {
    width: auto;
    margin: 2px 0 0;
}

.table-scroll {
    width: 100%;
    overflow: auto;
    max-height: calc(100vh - 260px);
}

.table-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #1e40af;
    box-shadow: 0 1px 0 #1e3a8a;
}

tr.is-filtered-out,
tr.is-off-page {
    content-visibility: hidden;
}

.col-filter-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.col-filter-label {
    cursor: pointer;
    user-select: none;
}

.col-filter-label.sort-asc::after {
    content: " ↑";
    font-weight: 700;
}

.col-filter-label.sort-desc::after {
    content: " ↓";
    font-weight: 700;
}

.col-filter-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: white;
    border-radius: 4px;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 11px;
    line-height: 1;
}

.col-filter-btn.active {
    background: #f59e0b;
    border-color: #f59e0b;
    color: #111827;
}

.col-filter-wrap {
    position: relative;
}

.col-filter-panel {
    display: none;
    position: absolute;
    top: 8px;
    left: 0;
    z-index: 5000;
    width: 280px;
    min-width: 260px;
    max-width: min(90vw, 360px);
    max-height: min(70vh, 520px);
    overflow: hidden;
    background: white;
    color: #1e293b;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    padding: 10px;
    flex-direction: column;
    box-sizing: border-box;
}

.col-filter-panel.open {
    display: flex;
}

.col-filter-search {
    margin: 0 0 8px;
    flex-shrink: 0;
}

.col-filter-actions {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.col-filter-list {
    flex: 1 1 auto;
    min-height: 100px;
    max-height: none;
    overflow: auto;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 6px;
}

.col-filter-item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    font-weight: normal;
    margin-bottom: 6px;
}

.col-filter-item input {
    width: auto;
    margin: 2px 0 0;
}

.col-filter-footer {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding-top: 4px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
}

.details-kv-table th {
    width: 40%;
}

.container {
    max-width: 1600px;
}

.landscape-picker {
    margin: 16px 0 24px;
    padding: 16px;
    background: #f8fafc;
    border: 1px solid #dbe4ee;
    border-radius: 10px;
}

.landscape-picker-label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #334155;
}

.landscape-picker-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.landscape-system-input {
    flex: 1 1 280px;
    min-width: 220px;
    margin: 0;
}

.landscape-empty {
    margin-top: 24px;
}

.landscape-overview-toolbar {
    margin: 0 0 12px;
}

.landscape-limit-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.landscape-limit-inline select {
    width: auto;
    margin: 0;
}

/* Адаптив для узких экранов / ноутбуков */
@media (max-width: 1100px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 14px 18px;
    }

    nav {
        flex-wrap: wrap;
        gap: 10px 14px;
        width: 100%;
    }

    .container {
        padding: 16px;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .graph-controls {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 768px) {
    header h2 {
        font-size: 20px;
    }

    .card {
        padding: 16px;
    }

    .toolbar,
    .actions-row,
    .graph-view-tools,
    .graph-toggles {
        flex-direction: column;
        align-items: stretch;
    }

    .btn,
    .btn-small {
        width: 100%;
        text-align: center;
    }

    table {
        font-size: 13px;
    }

    .table-scroll {
        margin: 0 -4px;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }
}

/* Быстрые ссылки на карточке */
.quick-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

/* Меню действий пользователей */
.actions-menu {
    position: relative;
    display: inline-block;
}

.actions-menu > summary {
    list-style: none;
    cursor: pointer;
}

.actions-menu > summary::-webkit-details-marker {
    display: none;
}

.actions-menu-panel {
    position: fixed;
    z-index: 3000;
    min-width: 260px;
    max-width: min(90vw, 320px);
    max-height: min(70vh, 420px);
    overflow: auto;
    padding: 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.actions-menu-panel .role-form,
.actions-menu-panel .inline-form {
    margin: 0;
}

.actions-menu-panel input,
.actions-menu-panel select {
    margin-bottom: 6px;
}

/* Diff импорта */
.import-diff-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.import-diff-item {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: #fff;
}

.import-diff-item strong {
    display: block;
    margin-bottom: 6px;
}

.import-diff-change {
    font-size: 13px;
    color: #475569;
    margin: 2px 0;
}

.import-diff-old {
    color: #b91c1c;
    text-decoration: line-through;
}

.import-diff-new {
    color: #047857;
    font-weight: 600;
}

.import-diff-table {
    width: 100%;
    margin-top: 8px;
    border-collapse: collapse;
    font-size: 13px;
}

.import-diff-table th,
.import-diff-table td {
    border: 1px solid #e2e8f0;
    padding: 6px 8px;
    text-align: left;
}

.import-diff-table th {
    background: #f1f5f9;
    color: #334155;
}
