/* ── Wikidata Graph Explorer ─────────────────────────────────────────────── */

/* Chalk theme tokens (mirrors static/css/edu-theme.css :root). This page is
   standalone (doesn't extend base.html), so the tokens are re-declared here
   rather than pulled in, with the same names/values so a future retheme is
   a one-line change.

   Scope note: the RIGHT panel's actual plot surface (.canvas-wrapper /
   #graphCanvas) is left on its original dark backdrop -- node fills, edge
   lines, and label colors are hardcoded in graph.js tuned for a dark stage
   (e.g. white node borders/labels, semi-transparent white edges), the same
   way poi_finder's map tiles are content, not brand decoration. Everything
   else -- including the chrome that floats ON TOP of that stage (legend
   frame, toolbar buttons, stats chip) -- is reskinned to chalk since those
   are opaque UI controls, not graph content. */
:root {
    --primary-dark: #F6F4F1;      /* page background ("paper") */
    --secondary-dark: #FFFFFF;    /* surface (panels, dropdown, chips) */
    --tertiary-dark: #EFEAE6;     /* elevated surface / hover */
    --accent-blue: #96305F;       /* "plum" -- primary accent */
    --accent-purple: #D9A441;     /* "gold" -- sparing highlight (loading state) */
    --accent-green: #2F7A6B;      /* "teal" -- sparing secondary accent (success state) */
    --accent-deep: #7A2650;       /* darker plum, for text-on-white */
    --text-primary: #1B1720;      /* ink */
    --text-secondary: #565160;    /* ink-soft */
    --text-muted: #8B8494;        /* ink-faint */
    --hairline: #E3DFD9;

    /* Left as its original dark value on purpose -- see scope note above. */
    --graph-stage-bg: #0d1117;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    background: var(--primary-dark);
    color: var(--text-primary);
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    overflow-x: hidden;
}

/* ── Page wrapper ────────────────────────────────────────────────────────── */

.page-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 10px 14px 0;
}

/* ── Two-column app layout ───────────────────────────────────────────────── */

.app-layout {
    display: flex;
    gap: 12px;
    flex: 1;
    min-height: 0;
    padding-bottom: 10px;
}

/* ── Left panel ──────────────────────────────────────────────────────────── */

.left-panel {
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--hairline) transparent;
}

.back-to-projects {
    display: inline-block;
    padding: 6px 12px;
    color: var(--accent-deep);
    text-decoration: none;
    font-size: 13px;
    border: 1px solid color-mix(in srgb, var(--accent-blue) 30%, transparent);
    border-radius: 6px;
    transition: background 0.2s, border-color 0.2s;
    align-self: flex-start;
}
.back-to-projects:hover { background: color-mix(in srgb, var(--accent-blue) 10%, transparent); border-color: var(--accent-blue); }

/* ── Header ─────────────────────────────────────────────────────────────── */

.project-header {
    padding: 4px 0;
}
.project-header h1 {
    font-family: 'Fraunces', Georgia, serif;
    font-size: clamp(1.3rem, 2vw, 1.6rem);
    font-weight: 700;
    color: var(--text-primary);
}
.project-header .subtitle {
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.4;
}

/* ── Search section ──────────────────────────────────────────────────────── */

.search-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-area {
    position: relative;
    width: 100%;
}

.search-row {
    display: flex;
    gap: 6px;
}

.search-row input {
    flex: 1;
    min-width: 0;
    padding: 11px 14px;
    background: var(--secondary-dark);
    border: 1px solid var(--hairline);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.search-row input:focus { border-color: var(--accent-blue); }
.search-row input::placeholder { color: var(--text-muted); font-size: 13px; }

.btn-search {
    padding: 11px 16px;
    background: var(--accent-blue);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
}
.btn-search:hover { background: var(--accent-deep); }
.btn-search:active { transform: scale(0.97); }

/* Suggestions — categorized accordion */

.suggestions-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.suggestion-category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    padding: 6px 4px;
    cursor: pointer;
    border-bottom: 1px solid var(--hairline);
    transition: color 0.2s;
    user-select: none;
}
.suggestion-category-header:hover { color: var(--text-secondary); }
.suggestion-category-header.open  { color: var(--accent-blue); border-bottom-color: color-mix(in srgb, var(--accent-blue) 35%, transparent); }

.suggestion-caret {
    font-size: 10px;
    transition: transform 0.2s;
}
.suggestion-category-header.open .suggestion-caret { transform: rotate(180deg); }

.suggestions-body {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 4px 0 8px;
}
.suggestions-body.open { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }

.suggestion-chip {
    padding: 8px 10px;
    background: color-mix(in srgb, var(--accent-blue) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent-blue) 30%, transparent);
    border-radius: 16px;
    color: var(--accent-deep);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.suggestion-chip:hover { background: color-mix(in srgb, var(--accent-blue) 18%, transparent); border-color: var(--accent-blue); }

/* Dropdown */

.search-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--secondary-dark);
    border: 1px solid var(--hairline);
    border-radius: 8px;
    overflow: hidden;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(27, 23, 32, 0.18);
    max-height: 280px;
    overflow-y: auto;
}

.dropdown-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--hairline);
    transition: background 0.15s;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: color-mix(in srgb, var(--accent-blue) 8%, transparent); }
.dropdown-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.dropdown-desc  { font-size: 11px; color: var(--text-secondary); margin-top: 2px;
                  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Status message -- semantic states mapped onto the chalk palette
   (gold = anticipation/loading, teal = success, deep plum = error/alert,
   plum = neutral info). */

.status-msg {
    display: none;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 6px;
}
.status-loading { color: color-mix(in srgb, var(--accent-purple) 75%, black); background: color-mix(in srgb, var(--accent-purple) 14%, transparent); border: 1px solid color-mix(in srgb, var(--accent-purple) 35%, transparent); }
.status-error   { color: var(--accent-deep); background: color-mix(in srgb, var(--accent-blue) 10%, transparent); border: 1px solid color-mix(in srgb, var(--accent-blue) 35%, transparent); }
.status-success { color: color-mix(in srgb, var(--accent-green) 80%, black); background: color-mix(in srgb, var(--accent-green) 12%, transparent); border: 1px solid color-mix(in srgb, var(--accent-green) 35%, transparent); }
.status-info    { color: var(--accent-deep); background: color-mix(in srgb, var(--accent-blue) 6%, transparent); border: 1px solid color-mix(in srgb, var(--accent-blue) 25%, transparent); }

/* ── Right panel ─────────────────────────────────────────────────────────── */

.right-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Empty state -- a plain placeholder card, not tied to any graph content
   color, so it gets the full chalk treatment. */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 300px;
    background: var(--secondary-dark);
    border: 1px dashed var(--hairline);
    border-radius: 12px;
    gap: 12px;
    color: var(--text-muted);
}
.empty-icon { font-size: 3rem; opacity: 0.6; }
.empty-state p { font-size: 14px; }

/* Graph container */

.graph-container {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* The plot surface itself -- kept on its original dark backdrop since
   graph.js hardcodes node/edge/label colors (white borders, semi-
   transparent white edges, etc.) tuned for a dark stage. Changing this
   background without touching graph.js would break edge/label legibility,
   the same reason poi_finder's map tile colors are left alone. */
.canvas-wrapper {
    position: relative;
    flex: 1;
    min-height: 400px;
    background: var(--graph-stage-bg);
    border: 1px solid var(--hairline);
    border-radius: 10px;
    overflow: hidden;
}

#graphCanvas {
    width: 100%;
    height: 100%;
}

/* ── Graph overlays ──────────────────────────────────────────────────────── */
/* These float on top of the dark plot surface but are our chrome (frame,
   buttons, chip), not graph content -- reskinned to chalk. Opaque/near-
   opaque light surfaces stay legible regardless of what's rendered
   underneath. Swatch colors inside the legend are per-category graph
   content (set inline in the template) and are left untouched. */

.graph-legend {
    position: absolute;
    bottom: 10px;
    left: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: color-mix(in srgb, var(--secondary-dark) 92%, transparent);
    border: 1px solid var(--hairline);
    border-radius: 8px;
    padding: 8px 10px;
    pointer-events: none;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    color: var(--text-secondary);
}
.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    flex-shrink: 0;
}
.legend-diamond {
    transform: rotate(45deg);
    width: 10px;
    height: 10px;
    border-radius: 1px;
}

.graph-toolbar {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 6px;
}

.btn-tool {
    padding: 6px 12px;
    background: color-mix(in srgb, var(--secondary-dark) 92%, transparent);
    border: 1px solid var(--hairline);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.btn-tool:hover { background: var(--secondary-dark); color: var(--accent-deep); border-color: color-mix(in srgb, var(--accent-blue) 40%, transparent); }

.graph-stats {
    position: absolute;
    bottom: 10px;
    right: 10px;
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    background: color-mix(in srgb, var(--secondary-dark) 88%, transparent);
    border: 1px solid var(--hairline);
    padding: 4px 10px;
    border-radius: 6px;
}
.stat-item span { color: var(--text-primary); font-weight: 600; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .page-wrapper { height: auto; }
    .app-layout { flex-direction: column; height: auto; }
    .left-panel { width: 100%; overflow-y: visible; }
.canvas-wrapper { min-height: 60vh; }
    .about-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .canvas-wrapper { min-height: 55vh; }
    .about-grid { grid-template-columns: 1fr; }
    .graph-stats { display: none; }
    .suggestions-body.open { grid-template-columns: 1fr; }
}
