/* =============================================================
   features.css — доступ, фильтры и граф связей
   ============================================================= */

.access-badge {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-height: 34px;
    margin-top: 8px;
    padding: 0 11px;
    border: 1px solid rgba(166, 166, 166, 0.24);
    border-left: 2px solid #777;
    background: rgba(5, 5, 6, 0.82);
    color: #aaa;
    font-family: monospace;
    font-size: 10px;
    letter-spacing: 0.08em;
    pointer-events: auto;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
}

.access-badge strong {
    font-size: 11px;
    color: #d2d2d2;
}

.access-badge[data-level="player"] {
    border-left-color: #8b8b8b;
}

.access-badge[data-level="archivist"] {
    border-color: rgba(87, 232, 137, 0.3);
    border-left-color: #57e889;
}

.access-badge[data-level="archivist"] strong {
    color: #91e9ae;
}

.access-badge[data-level="storyteller"] {
    border-color: rgba(197, 31, 36, 0.45);
    border-left-color: var(--blood-bright);
    background: rgba(62, 7, 10, 0.72);
}

.access-badge[data-level="storyteller"] strong {
    color: #f06e72;
    text-shadow: 0 0 10px rgba(197, 31, 36, 0.45);
}

#search-widget {
    display: block;
    width: min(760px, calc(100vw - 40px));
    padding: 0;
}

.search-command-row {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 46px;
    padding: 8px 12px;
}

.search-prompt {
    flex: 0 0 auto;
    white-space: nowrap;
}

#terminal-search {
    flex: 1;
    min-width: 90px;
    width: auto;
}

.search-filter-toggle,
.search-filter-reset {
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid rgba(197, 31, 36, 0.32);
    border-radius: 1px;
    background: rgba(20, 5, 6, 0.62);
    color: #bb777a;
    font-family: monospace;
    font-size: 10px;
    cursor: pointer;
    transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.search-filter-toggle:hover,
.search-filter-toggle:focus-visible,
.search-filter-toggle[aria-expanded="true"],
.search-filter-reset:hover,
.search-filter-reset:focus-visible {
    color: #fff;
    border-color: var(--blood-bright);
    background: rgba(138, 3, 3, 0.22);
    outline: none;
}

.search-result-count {
    flex: 0 0 auto;
    min-width: 58px;
    color: #756467;
    font-family: monospace;
    font-size: 9px;
    text-align: right;
}

.search-filters {
    display: grid;
    grid-template-columns: repeat(5, minmax(100px, 1fr)) auto;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid rgba(197, 31, 36, 0.18);
    background: rgba(2, 2, 3, 0.74);
}

.search-filters.hidden {
    display: none;
}

.search-filters label {
    display: grid;
    gap: 5px;
    color: #7f6c6f;
    font-family: monospace;
    font-size: 9px;
    letter-spacing: 0.08em;
}

.search-filters select {
    width: 100%;
    min-height: 40px;
    padding: 0 28px 0 9px;
    border: 1px solid rgba(166, 166, 166, 0.22);
    border-radius: 1px;
    background: #070708;
    color: #bdb0b2;
    font-family: monospace;
    font-size: 10px;
}

.search-filters select:focus-visible {
    border-color: var(--blood-bright);
    outline: 2px solid rgba(197, 31, 36, 0.2);
    outline-offset: 1px;
}

.search-filter-reset {
    align-self: end;
    min-height: 40px;
}

#search-suggestions {
    max-height: min(430px, 58vh);
}

#search-suggestions li {
    min-height: 0;
    padding: 0;
}

#search-suggestions li:hover {
    padding-left: 0;
    background: transparent;
}

#search-suggestions li > button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    min-height: 54px;
    padding: 8px 14px;
    border: 0;
    border-bottom: 1px dashed #242024;
    background: transparent;
    color: #b4aaac;
    font-family: monospace;
    text-align: left;
    cursor: pointer;
    transition: color 160ms ease, background 160ms ease, padding-left 160ms ease;
}

#search-suggestions li > button:hover,
#search-suggestions li > button:focus-visible,
#search-suggestions li > button.is-active {
    padding-left: 19px;
    color: #f0dfe0;
    background: linear-gradient(90deg, rgba(138, 3, 3, 0.24), rgba(138, 3, 3, 0.06));
    outline: none;
}

.search-result-copy {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.search-result-copy strong,
.search-result-copy small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-copy strong {
    font-size: 12px;
}

.search-result-copy small {
    color: #71696a;
    font-size: 9px;
}

.search-empty {
    padding: 16px !important;
    color: #666 !important;
    font-family: monospace;
    pointer-events: none;
}

.relations-call-btn {
    width: auto;
    min-width: 230px;
    min-height: 46px;
    margin: 0;
    padding: 0 18px;
    border: 1px solid rgba(197, 31, 36, 0.28);
    border-left: 0;
    border-right: 0;
    background: transparent;
    color: #a88f91;
    font-family: monospace;
    cursor: pointer;
    transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.dossier-graph-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-top: 18px;
    padding: 14px 0;
    border-top: 1px dashed rgba(197, 31, 36, 0.26);
    border-bottom: 1px dashed rgba(197, 31, 36, 0.18);
}

.dossier-graph-copy {
    display: grid;
    gap: 5px;
    min-width: 0;
    font-family: monospace;
}

.dossier-graph-copy span {
    color: #c6aeb0;
    font-size: 10px;
    letter-spacing: 0.12em;
}

.dossier-graph-copy small {
    color: #6f6668;
    font-size: 9px;
    line-height: 1.45;
}

.relations-call-btn:hover,
.relations-call-btn:focus-visible {
    color: #fff;
    border-color: var(--blood-bright);
    background: linear-gradient(90deg, transparent, rgba(138, 3, 3, 0.16), transparent);
    outline: none;
}

.relations-panel {
    top: 50%;
    right: -980px;
    width: min(920px, calc(100vw - 40px));
    height: min(90dvh, 820px);
    padding: 26px;
    overflow: hidden;
    flex-direction: column;
    transform: translateY(-50%);
    border-color: rgba(255, 255, 255, 0.09);
    border-top-color: rgba(197, 31, 36, 0.5);
    box-shadow: -26px 0 70px rgba(0, 0, 0, 0.72);
    transition: right 300ms cubic-bezier(.22, 1, .36, 1);
    z-index: 10020;
}

.relations-panel.open {
    right: 20px;
}

.relations-subtitle {
    margin: 2px 0 12px;
    color: #a99c9f;
    font-family: monospace;
    font-size: 11px;
    letter-spacing: 0.08em;
}

.relations-hint {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    margin-bottom: 12px;
    padding: 0 14px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-left: 2px solid rgba(197, 31, 36, 0.72);
    background: linear-gradient(90deg, rgba(138, 3, 3, 0.1), rgba(255, 255, 255, 0.015));
    color: #b9adaf;
    font-family: monospace;
    font-size: 9px;
    letter-spacing: 0.08em;
}

.relations-hint-signal {
    width: 7px;
    height: 7px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #c51f24;
    box-shadow: 0 0 10px rgba(197, 31, 36, 0.8);
}

.relations-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin-bottom: 10px;
    font-family: monospace;
    font-size: 9px;
    color: #9e9294;
}

.relations-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.relations-legend span::before {
    content: "";
    width: 18px;
    height: 2px;
    background: #777;
}

.relations-legend span[data-relation="sire"]::before { background: #b8b8b8; }
.relations-legend span[data-relation="ally"]::before { background: #57a878; }
.relations-legend span[data-relation="enemy"]::before { background: #c51f24; }
.relations-legend span[data-relation="control"]::before { background: #8d5eb1; }

.relations-graph {
    position: relative;
    width: 100%;
    flex: 1;
    height: auto;
    min-height: 470px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-top-color: rgba(197, 31, 36, 0.34);
    background:
        radial-gradient(circle at 50% 50%, rgba(138, 3, 3, 0.09), transparent 25%),
        linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
        #050506;
    background-size: auto, 32px 32px, 32px 32px, auto;
}

.relations-lines,
.relations-nodes {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.relations-lines {
    z-index: 1;
    pointer-events: none;
}

.relations-nodes {
    z-index: 2;
    pointer-events: none;
}

.relations-lines line {
    stroke: #777;
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
    opacity: 0.66;
}

.relations-lines line[data-relation="sire"] { stroke: #b8b8b8; }
.relations-lines line[data-relation="ally"] { stroke: #57a878; }
.relations-lines line[data-relation="enemy"] { stroke: #c51f24; }
.relations-lines line[data-relation="control"] { stroke: #8d5eb1; stroke-dasharray: 7 5; }

.relation-node {
    position: absolute;
    z-index: 2;
    display: grid;
    place-content: center;
    gap: 4px;
    width: 142px;
    min-height: 72px;
    padding: 8px 10px;
    transform: translate(-50%, -50%);
    border: 1px solid #555;
    border-radius: 0;
    background: linear-gradient(145deg, rgba(18, 16, 17, 0.98), rgba(7, 7, 8, 0.98));
    color: #d2cacc;
    font-family: monospace;
    text-align: center;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.44);
}

button.relation-node {
    pointer-events: auto;
    cursor: pointer;
    touch-action: manipulation;
    transition: color 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button.relation-node:hover,
button.relation-node:focus-visible {
    border-color: var(--blood-bright);
    background: rgba(40, 8, 10, 0.97);
    box-shadow: 0 0 0 2px rgba(197, 31, 36, 0.18), 0 14px 28px rgba(0, 0, 0, 0.54);
    outline: none;
    transform: translate(-50%, -50%) scale(1.045);
}

button.relation-node.is-opening {
    pointer-events: none;
    border-color: #e7dfe0;
    background: rgba(74, 9, 13, 0.98);
    color: #fff;
    opacity: 0.72;
    transform: translate(-50%, -50%) scale(0.97);
}

.relation-node.is-unavailable {
    cursor: default;
    border-style: dashed;
    opacity: 0.5;
}

.relation-node strong {
    overflow-wrap: anywhere;
    font-size: 12px;
    line-height: 1.2;
}

.relation-node small {
    color: #968a8c;
    font-size: 8px;
    line-height: 1.25;
}

.relation-node-action {
    color: #b58f93;
    font-size: 8px;
    letter-spacing: 0.07em;
    line-height: 1.2;
}

button.relation-node:hover .relation-node-action,
button.relation-node:focus-visible .relation-node-action {
    color: #f0b8bb;
}

.relation-node[data-relation="sire"] { border-color: rgba(184, 184, 184, 0.58); }
.relation-node[data-relation="ally"] { border-color: rgba(87, 168, 120, 0.62); }
.relation-node[data-relation="enemy"] { border-color: rgba(197, 31, 36, 0.72); }
.relation-node[data-relation="control"] { border-color: rgba(141, 94, 177, 0.68); }

.relation-node-center {
    width: 176px;
    min-height: 88px;
    border-color: var(--blood-bright);
    background: linear-gradient(145deg, rgba(69, 8, 12, 0.99), rgba(35, 5, 8, 0.99));
    color: #fff;
    box-shadow: 0 0 28px rgba(197, 31, 36, 0.24);
}

/* Independent tactical-layer dock: never participates in the search layout. */
#layer-controls {
    position: fixed;
    inset: auto auto clamp(14px, 2vw, 24px) clamp(14px, 2.2vw, 28px);
    z-index: 18;
    display: block;
    width: min(330px, calc(100vw - 28px));
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    pointer-events: auto;
    transition: opacity 180ms ease, transform 180ms ease;
}

body.search-expanded #layer-controls,
body.relations-open #layer-controls {
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
}

.layer-dock-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    width: 100%;
    min-height: 46px;
    padding: 0 13px;
    border: 0;
    border-left: 2px solid var(--blood-bright);
    background: rgba(8, 8, 9, 0.96);
    color: #c8bfc0;
    font-family: monospace;
    font-size: 10px;
    letter-spacing: 0.08em;
    text-align: left;
    cursor: pointer;
}

.layer-dock-toggle:hover,
.layer-dock-toggle:focus-visible {
    color: #fff;
    background: rgba(38, 7, 9, 0.96);
    outline: 2px solid rgba(197, 31, 36, 0.24);
    outline-offset: -2px;
}

.layer-dock-state {
    color: #866f72;
    font-size: 8px;
}

.layer-dock-body {
    padding: 8px;
    border-top: 1px solid rgba(197, 31, 36, 0.18);
    background: rgba(3, 3, 4, 0.94);
}

#layer-controls[data-collapsed="true"] .layer-dock-body {
    display: none;
}

.layer-button-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

#layer-controls .layer-btn {
    width: 100%;
    min-height: 44px;
    padding: 8px 8px 8px 13px;
    font-size: 9px;
}

#layer-controls #layer-legend {
    position: static;
    width: auto;
    min-width: 0;
    margin: 8px 0 0;
    box-shadow: none;
}

.relations-empty {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    place-items: center;
    color: #6c6264;
    font-family: monospace;
    font-size: 12px;
    letter-spacing: 0.08em;
    pointer-events: none;
}

.relations-empty.hidden {
    display: none;
}

@media (max-width: 900px) {
    .search-filters {
        grid-template-columns: repeat(3, minmax(110px, 1fr));
    }

    .relations-panel {
        top: 0;
        right: -100vw;
        width: 100vw;
        height: 100dvh;
        padding: 18px;
        transform: none;
    }

    .relations-panel.open {
        right: 0;
    }

    .relations-graph {
        min-height: 0;
    }
}

@media (max-width: 640px) {
    .access-badge {
        min-height: 30px;
        margin-top: 5px;
    }

    #search-widget {
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    .search-command-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        gap: 6px;
    }

    .search-prompt {
        grid-column: 1 / -1;
        width: auto;
        font-size: 9px;
    }

    #terminal-search {
        width: 100%;
        min-width: 0;
    }

    .search-result-count {
        min-width: 52px;
    }

    .search-filters {
        grid-template-columns: 1fr 1fr;
        max-height: 46dvh;
        overflow-y: auto;
    }

    .search-filter-reset {
        grid-column: 1 / -1;
    }

    .relations-panel {
        left: 0;
        right: auto;
        box-sizing: border-box;
        max-width: 100vw;
        padding: 14px;
    }

    .relations-legend {
        gap: 6px 10px;
    }

    .relations-hint {
        min-height: 38px;
        padding: 0 10px;
        font-size: 8px;
    }

    .relations-graph {
        height: calc(100% - 130px);
    }

    .relation-node {
        width: 96px;
        min-height: 62px;
        padding: 5px;
    }

    .relation-node-center {
        width: 124px;
        min-height: 76px;
    }

    .relation-node strong {
        font-size: 9px;
    }

    .relation-node small {
        font-size: 7px;
    }

    .relation-node-action {
        font-size: 6px;
    }

    .dossier-graph-entry {
        align-items: stretch;
        flex-direction: column;
    }

    .relations-call-btn {
        width: 100%;
        min-width: 0;
    }

    #layer-controls {
        inset: auto 10px 10px;
        width: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .relations-panel,
    .relation-node,
    #search-suggestions li > button {
        transition-duration: 0.01ms !important;
    }
}
