/* static/css/graph.css – Overhauled (lean) */

/* --- 1) PAGE & SEARCH BAR --- */
#graph-search-section {
    max-width: 1600px;
    margin: 2rem auto;
    padding: 2rem;
    background-color: #e0dcc2;
    border-radius: 12px;
}

#graph-search-section h2 {
    text-align: center;
    color: #092407;
    margin-bottom: .75rem;
}

#graph-search-section .description {
    text-align: center;
    color: #4a4a4a;
    margin-bottom: 2rem;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
}

.search-container {
    display: flex;
    justify-content: center;
}

#graph-search-form {
    display: flex;
    width: 100%;
    max-width: 650px;
    border-radius: 50px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, .1);
}

.search-input-wrapper {
    display: flex;
    flex-grow: 1;
}

#graph-search-input {
    flex-grow: 1;
    padding: 15px 25px;
    font-size: 1.1em;
    border: none;
    outline: none;
}

#graph-search-btn {
    padding: 0 30px;
    font-size: 1.1em;
    cursor: pointer;
    border: none;
    background-color: #132e04;
    color: #fff;
}

#graph-search-category {
    padding: 0 10px 0 20px;
    font-size: 1em;
    border: none;
    background-color: #f0f0f0;
    color: #333;
    border-right: 1px solid #ddd;
    outline: none;
    cursor: pointer;
}

.options-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 1rem;
    margin-bottom: 1rem;
}

#limit-input,
#node-limit-input {
    width: 64px;
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    text-align: center;
}

/* --- 2) MESSAGE AREA (pill + multi-flash) --- */
#graph-message-area {
    position: static;
    z-index: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding-left: 12px;
    padding-bottom: 12px;
    --pill-bg: #f7f6f0;
    --pill-fg: #374151;
    --pill-flash: #fff3c4;
}

#graph-message-area p {
    background: var(--pill-bg);
    color: var(--pill-fg);
    display: inline-block;
    padding: 8px 14px;
    border-radius: 999px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
    font-style: italic;
    margin: 0;
    text-align: center;
}

/* multi-flash */
@keyframes msg-flash {
    0% {
        background-color: var(--pill-bg);
        box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
        transform: scale(1);
    }

    50% {
        background-color: var(--pill-flash);
        box-shadow: 0 0 0 6px var(--pill-ring, rgba(250, 204, 21, .35));
        transform: scale(var(--flash-scale, 1.03));
    }

    100% {
        background-color: var(--pill-bg);
        box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
        transform: scale(1);
    }
}

#graph-message-area p.flash {
    animation-name: msg-flash;
    animation-duration: var(--flash-duration, 700ms);
    animation-iteration-count: var(--flash-count, 3);
    animation-timing-function: ease-in-out;
    animation-direction: alternate;
    will-change: background-color, box-shadow, transform;
}

#graph-message-area p.state-info {
    --pill-flash: #fff3c4;
    --pill-ring: rgba(234, 179, 8, .40);
}

#graph-message-area p.state-success {
    --pill-flash: #dcfce7;
    --pill-ring: rgba(34, 197, 94, .45);
}

#graph-message-area p.state-error {
    --pill-flash: #fee2e2;
    --pill-ring: rgba(239, 68, 68, .45);
}

/* Refresh button (centered below the message) */
#refresh-graph-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 10px auto 0;
    padding: 8px 16px;
    font-size: .95em;
    font-weight: 600;
    background: #132e04;
    color: #fff;
    border: 1px solid rgba(0, 0, 0, .15);
    border-radius: 22px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .1);
    position: static;
    z-index: auto;
}

#refresh-graph-btn:hover {
    background: #1e4d08;
}

#refresh-graph-btn:active {
    transform: translateY(1px);
}

#refresh-graph-btn:focus-visible {
    outline: 2px solid #73b36b;
    outline-offset: 2px;
}

#refresh-graph-btn.hidden {
    display: none;
}

/* --- 3) FIXED HEIGHT LAYOUT --- */
#graph-main-content {
    display: flex;
    gap: 20px;
    align-items: stretch;
}

/* fixed heights: keep cy-container at 82vh, extend parent to fit session bar */
#cy-container {
    height: 82vh;
}

#graph-display-area,
#search-results-container {
    height: calc(82vh + 56px);
}

/* Left panel */
#search-results-container {
    flex-basis: 360px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    transition: flex-basis .4s ease-in-out, opacity .3s ease;
}

#search-results-container.closed {
    flex-basis: 0;
    border-width: 0;
    opacity: 0;
    padding: 0;
    margin: 0;
}

.panel-header {
    padding: 12px 14px;
    background: #f7f6f0;
    border-bottom: 1px solid #ddd;
    color: #092407;
}

/* Panel header: lay out title, tabs, and mode toggle */
.panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-header h3 {
    margin-right: auto;
}

/* Tabs */
.panel-tabs {
    display: flex;
    gap: 6px;
}

.panel-tabs .tab {
    padding: 6px 10px;
    font-size: 13px;
    border-radius: 8px;
    border: 1px solid #d6d6d6;
    background: #fafafa;
    cursor: pointer;
}

.panel-tabs .tab:hover {
    background: #f0f0f0;
}

.panel-tabs .tab.active {
    background: #e9e8e1;
    border-color: #c9c9c9;
    font-weight: 600;
}

/* Replace/Add mode toggle */
.result-mode {
    display: flex;
    gap: 10px;
    align-items: center;
    border: 1px solid #e6e6e6;
    background: #fff;
    padding: 6px 8px;
    border-radius: 8px;
}

.result-mode .mode-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: #444;
}

.result-mode input[type="radio"] {
    transform: translateY(1px);
}

.panel-body {
    overflow-y: auto;
    flex: 1;
}

/* Results list */
#search-results-accordion .accordion-button {
    width: 100%;
    padding: 14px;
    background: #fff;
    border: none;
    text-align: left;
    font-size: 1em;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #333;
    border-bottom: 1px solid #eee;
}

#search-results-accordion .accordion-button:hover {
    background: #f5f5f5;
}

#search-results-accordion .accordion-button.active {
    background: #e9e8e1;
    font-weight: bold;
}

.result-type {
    padding: 3px 8px;
    border-radius: 12px;
    font-size: .8em;
    color: #fff;
}

/* Control panel core */
#control-panel.hidden {
    display: none;
}

.panel-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-bottom: 1px solid #eee;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 5;
}

#node-filter-input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
}

.panel-stats {
    font-size: .9em;
    color: #666;
    white-space: nowrap;
}

.panel-warning {
    margin: 6px 10px;
    padding: 8px 10px;
    border-radius: 6px;
    background: #fff8e1;
    color: #6b4e00;
    border: 1px solid #ffe0a3;
}

/* Bulk controls (sticky under toolbar) */
.panel-bulk {
    position: sticky;
    top: 48px;
    z-index: 4;
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    padding: 8px 10px 6px;
}

.bulk-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 6px;
}

.bulk-actions>button {
    padding: 6px 10px;
    font-size: 12.5px;
    border: 1px solid #d6d6d6;
    background: #fafafa;
    border-radius: 8px;
    cursor: pointer;
}

.bulk-actions>button:hover {
    background: #f0f0f0;
}

.panel-bulk-row {
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 1px solid #201e1e;
    margin-top: 6px;
    padding-top: 8px;
}

.type-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;
}

.type-chips .type-chip {
    padding: 5px 9px;
    font-size: 12px;
    border-radius: 999px;
    border: 1px solid #e1e1e1;
    background: #fff;
    cursor: pointer;
}

.type-chips .type-chip[data-type="Plant"] {
    border-color: #2ca02c33;
}

.type-chips .type-chip[data-type="Phytochemical"] {
    border-color: #ff7f0e33;
}

.type-chips .type-chip[data-type="Disease"] {
    border-color: #d6272833;
}

.type-chips .type-chip[data-type="Formulation"] {
    border-color: #1f77b433;
}

.type-chips .type-chip:hover {
    background: #f7f7f7;
}

/* Visual state for type chips */
.type-chips .type-chip.is-on {
    background: #f0fdf4;
    /* light green */
    border-color: #16a34a66;
    box-shadow: inset 0 0 0 1px #16a34a33;
}

.type-chips .type-chip.is-off {
    background: #fef2f2;
    /* light red */
    border-color: #dc262666;
    color: #7f1d1d;
}

.type-chips .type-chip.is-mixed {
    background: #fff7ed;
    /* light orange */
    border-style: dashed;
    border-color: #fb923c99;
}

.bulk-actions .danger {
    border-color: #dc2626;
    color: #b91c1c;
    background: #fee2e2;
}

.bulk-actions .danger:hover {
    background: #fecaca;
}

.bulk-overflow {
    position: relative;
}

.bulk-more-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid #d6d6d6;
    background: #fafafa;
    cursor: pointer;
    font-weight: 700;
}

.bulk-more-btn:hover {
    background: #f0f0f0;
}

.bulk-menu {
    position: absolute;
    right: 0;
    top: 32px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .15);
    padding: 6px;
    min-width: 180px;
}

.bulk-menu.hidden {
    display: none;
}

.bulk-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    font-size: 13px;
}

.bulk-menu button:hover {
    background: #f5f5f5;
}

.node-list {
    padding: 8px;
}

.node-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px;
    border-radius: 6px;
    cursor: default;
}

.node-row:hover {
    background: #f7f7f7;
}

.node-row input[type="checkbox"] {
    transform: translateY(1px);
}

.node-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, .2);
}

.node-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- 4) GRAPH AREA & TOGGLE BUTTON --- */
#graph-display-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

#toggle-results-btn {
    position: absolute;
    top: 0;
    left: -16px;
    z-index: 200;
    width: 32px;
    height: 60px;
    padding: 0;
    background: #092407;
    color: #fff;
    border: 1px solid #ddd;
    border-left: none;
    border-radius: 0 15px 15px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 2px 0 5px rgba(0, 0, 0, .1);
    transition: all .4s ease-in-out;
}

#toggle-results-btn:hover {
    background: #1e4d08;
}

#toggle-results-btn svg {
    transition: transform .4s ease-in-out;
}

#search-results-container.closed+#graph-display-area #toggle-results-btn {
    left: 0;
}

#search-results-container.closed+#graph-display-area #toggle-results-btn svg {
    transform: rotate(180deg);
}

#cy-container {
    position: relative;
    border: 1px solid #e0dcc2;
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
}

#cy-graph {
    width: 100%;
    height: 100%;
}

#graph-zoom-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
#graph-zoom-controls .zoom-btn.is-active {
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35);
}

.zoom-btn {
    width: 40px;
    height: 40px;
    background: #132e04;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .5);
    border-radius: 50%;
    font-size: 22px;
    text-align: center;
    cursor: pointer;
}

/* --- 5) INFO PANEL --- */
#info-panel {
    position: fixed;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    z-index: 300;
    width: 380px;
    height: 68vh;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, .2);
    display: flex;
    flex-direction: column;
    transition: opacity .3s, transform .3s;
    resize: both;
    overflow: auto;
}

#info-panel.hidden {
    opacity: 0;
    transform: translateY(-50%) translateX(100%);
    pointer-events: none;
}

#info-panel.undocked {
    position: fixed;
    right: auto;
    transform: none;
}

#info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #f7f6f0;
    border-bottom: 1px solid #ddd;
    cursor: move;
}

#info-header h3 {
    margin: 0;
}

#info-content {
    padding: 12px;
    overflow: auto;
    flex: 1;
}

#close-info-btn,
#dock-info-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
}

.info-table {
    width: 100%;
    border-collapse: collapse;
}

.info-table th,
.info-table td {
    padding: 8px;
    text-align: left;
    border-bottom: 1px solid #eee;
    vertical-align: top;
}

.info-table th.section {
    background: #f2f2f2;
    text-align: center;
}

/* --- 6) CONTEXT MENU (right-click) --- */
#context-menu {
    position: absolute;
    z-index: 400;
    min-width: 220px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .15);
    overflow: hidden;
}

#context-menu.hidden {
    display: none;
}

#context-menu-list {
    list-style: none;
    margin: 0;
    padding: 6px 0;
    max-height: 60vh;
    overflow: auto;
}

#context-menu-list li {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
}

#context-menu-list li:hover {
    background: #f5f5f5;
}

#context-menu-list li.danger {
    color: #b00020;
}

#context-menu-list li.muted {
    color: #777;
    cursor: default;
}

/* --- 7) FULLSCREEN --- */
#cy-container:fullscreen,
#graph-display-area:fullscreen {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
}

#cy-container:fullscreen #cy-graph {
    height: 100vh;
}

/* --- utility --- */
.hidden {
    display: none !important;
}

/* Keep the title clear of the floating graph toggle */
#search-results-container .panel-header {
    padding-right: 44px;
    /* ~toggle width + breathing room */
}

/* Two-row header: title on top, controls under it */
.panel-subheader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    background: #fff;
    border-bottom: 1px solid #eee;
}

/* Tabs */
.panel-tabs {
    display: flex;
    gap: 8px;
}

.tab-btn {
    padding: 6px 10px;
    border: 1px solid #ddd;
    background: #fff;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
}

.tab-btn.active {
    background: #e9e8e1;
}

/* Replace/Add block (hide in Control tab via JS) */
.result-mode {
    display: flex;
    align-items: center;
    gap: 12px;
}

.result-mode.hidden {
    display: none;
}

.result-mode label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #444;
}

/* Prevent long-press callout / selection in the graph on mobile */
#cy-container,
#cy-graph {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
    /* prevents some default gestures that can trigger context UI */
}
/* Session & Export bar */
#session-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 8px 10px;
    background: #fff;
    border: 1px solid #e0dcc2;
    border-radius: 10px;
}

#session-bar .spacer {
    flex: 1;
}

#session-bar button {
    padding: 6px 10px;
    font-size: 13px;
    border: 1px solid #d6d6d6;
    background: #fafafa;
    border-radius: 8px;
    cursor: pointer;
}

#session-bar button:hover {
    background: #f0f0f0;
}

/* bulk menu separator */
.bulk-menu .menu-sep {
    height: 1px;
    background: #eee;
    margin: 6px 4px;
}