/* Cherry Harvest — modern frontend.
 *
 * Design: clean, light surface with deep cherry accent. System font stack,
 * generous spacing, compact-but-readable info tables. Layout is a 3-row
 * flex shell (topbar / main / footer) with a sidebar + graph split inside
 * main. Element IDs and class names consumed by the JS layer are
 * preserved verbatim (canvas, legend, infoCommit*, infoEdge*,
 * .tooltip-infobox, .tooltip-window). */

/* Theming.
 *
 * Light is the default: vars on :root. Dark is applied either via an
 * explicit data-theme="dark" attribute (user toggle, persisted in
 * localStorage by index.html) or via prefers-color-scheme when no
 * override is set. The graph canvas intentionally stays on a lighter
 * surface in dark mode — vis-network's default node/edge styling is
 * tuned for light backgrounds, so we keep it readable rather than
 * fighting it. */

:root {
    --bg:            #f7f5f4;
    --surface:       #ffffff;
    --surface-2:     #faf7f6;
    --surface-3:     #f1ebe9;
    --border:        #e6dcd8;
    --border-strong: #d6c8c2;
    --ink:           #1f1416;
    --ink-2:         #4a3c3f;
    --ink-3:         #7a6c70;
    --muted:         #9a8d91;

    --cherry:        #b91c2c;
    --cherry-deep:   #7a1320;
    --cherry-soft:   #fdecec;
    --truss:         #2f5fb1;
    --truss-deep:    #1f3f73;

    --accent:        var(--cherry);
    --accent-ink:    #ffffff;

    /* Canvas surface. In dark mode we keep the graph card light so
     * vis-network's labels and arrows stay legible; --canvas-bg
     * controls only the canvas itself, --graph-surface the card chrome
     * around it. */
    --canvas-bg:     #ffffff;
    --graph-surface: var(--surface);
    --graph-border:  var(--border);

    --legend-bg:     rgba(255, 255, 255, 0.95);

    --radius-sm:     6px;
    --radius:        10px;
    --radius-lg:     14px;

    --shadow-sm:     0 1px 2px rgba(31, 20, 22, 0.04);
    --shadow:        0 4px 14px rgba(31, 20, 22, 0.06), 0 1px 2px rgba(31, 20, 22, 0.04);

    --font-sans:     ui-sans-serif, system-ui, -apple-system, "Segoe UI",
                     Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono:     ui-monospace, SFMono-Regular, Menlo, Consolas,
                     "Liberation Mono", monospace;

    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg:            #14100f;
    --surface:       #1d1719;
    --surface-2:     #251e20;
    --surface-3:     #2e2528;
    --border:        #382e30;
    --border-strong: #4a3d40;
    --ink:           #f3eaec;
    --ink-2:         #d2c4c7;
    --ink-3:         #9c8e92;
    --muted:         #6f6266;

    --cherry:        #ee4c5c;
    --cherry-deep:   #b91c2c;
    --cherry-soft:   rgba(238, 76, 92, 0.18);
    --truss:         #6b8fd6;
    --truss-deep:    #2f5fb1;

    --canvas-bg:     #f6f3f2;
    --graph-surface: #1d1719;
    --graph-border:  #382e30;

    --legend-bg:     rgba(29, 23, 25, 0.92);

    --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow:        0 6px 18px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.35);

    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg:            #14100f;
        --surface:       #1d1719;
        --surface-2:     #251e20;
        --surface-3:     #2e2528;
        --border:        #382e30;
        --border-strong: #4a3d40;
        --ink:           #f3eaec;
        --ink-2:         #d2c4c7;
        --ink-3:         #9c8e92;
        --muted:         #6f6266;

        --cherry:        #ee4c5c;
        --cherry-deep:   #b91c2c;
        --cherry-soft:   rgba(238, 76, 92, 0.18);
        --truss:         #6b8fd6;
        --truss-deep:    #2f5fb1;

        --canvas-bg:     #f6f3f2;
        --graph-surface: #1d1719;
        --graph-border:  #382e30;

        --legend-bg:     rgba(29, 23, 25, 0.92);

        --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.35);
        --shadow:        0 6px 18px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.35);

        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

/* Fluid base. All rem-based sizes downstream scale with the viewport.
 * The upper bound is set high (40px) on purpose: browser zoom-out turns
 * a 1920px monitor into a 3840+ CSS-px viewport, and we want the rem to
 * keep growing past that point so the responsive ResizeObserver on the
 * legend keeps firing. Anchor points: ~16px @ 1920, ~24px @ 3840,
 * ~32px @ 6400 (Firefox's 30% zoom on a 1920 screen). */
html {
    font-size: clamp(12px, 0.6rem + 0.35vw, 40px);
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a {
    color: var(--cherry);
    text-decoration: none;
    transition: color 120ms ease;
}
a:hover { color: var(--cherry-deep); text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

/* ---------- shell ---------- */

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- topbar ---------- */

.topbar {
    height: 3.75rem;
    padding: 0 1.75rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-mark {
    width: 2.375rem;
    height: 2.375rem;
    border-radius: 10px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.brand-mark img {
    display: block;
    width: 1.75rem;
    height: 1.75rem;
    object-fit: contain;
    image-rendering: -webkit-optimize-contrast;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}
.brand-title {
    font-size: 1.1875rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink);
}
.brand-tag {
    font-size: 0.78rem;
    color: var(--ink-3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.topbar__nav {
    display: flex;
    align-items: center;
    gap: 1.375rem;
}
.topbar__nav a {
    color: var(--ink-2);
    font-size: 0.9375rem;
    font-weight: 500;
}
.topbar__nav a:hover { color: var(--cherry); text-decoration: none; }

/* theme toggle */
.theme-toggle {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--ink-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.theme-toggle:hover {
    background: var(--surface-3);
    color: var(--cherry);
    border-color: var(--border-strong);
}
.theme-toggle:focus-visible {
    outline: none;
    border-color: var(--cherry);
    box-shadow: 0 0 0 3px var(--cherry-soft);
}
.theme-icon { display: none; }
:root[data-theme="light"] .theme-icon--moon,
:root:not([data-theme]) .theme-icon--moon { display: block; }
:root[data-theme="dark"] .theme-icon--sun { display: block; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .theme-icon--moon { display: none; }
    :root:not([data-theme]) .theme-icon--sun  { display: block; }
}

/* ---------- main layout ---------- */

.layout {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(22.5rem, 26.25rem) 1fr;
    grid-template-rows: 1fr;
    gap: 1.25rem;
    padding: 1.25rem;
    min-height: 37.5rem;
}

/* ---------- sidebar ---------- */

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.125rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

.card__title {
    font-size: 0.9375rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-3);
    margin-bottom: 0.25rem;
}

.card__hint {
    margin: 0 0 0.875rem;
    color: var(--ink-3);
    font-size: 0.875rem;
}

/* form fields */
.field { display: flex; flex-direction: column; gap: 0.375rem; margin-bottom: 0.75rem; }
.field:last-child { margin-bottom: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.field-hint {
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    color: var(--ink-3);
    font-size: 0.6875rem;
    margin-left: 0.25rem;
}
.field-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.25rem;
}
.btn-primary {
    appearance: none;
    border: none;
    cursor: pointer;
    background: var(--cherry);
    color: var(--accent-ink);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.5rem 1.125rem;
    border-radius: var(--radius-sm);
    transition: background 120ms ease, box-shadow 120ms ease, transform 80ms ease;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover    { background: var(--cherry-deep); }
.btn-primary:active   { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: progress; }
.btn-primary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--cherry-soft);
}
.btn-secondary {
    appearance: none;
    cursor: pointer;
    background: transparent;
    color: var(--cherry-deep);
    border: 1px solid var(--cherry);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.4375rem 1rem;
    border-radius: var(--radius-sm);
    transition: background 120ms ease, box-shadow 120ms ease, transform 80ms ease;
}
.btn-secondary:hover    { background: var(--cherry-soft); }
.btn-secondary:active   { transform: translateY(1px); }
.btn-secondary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--cherry-soft);
}
.filter-status {
    font-size: 0.78rem;
    color: var(--ink-3);
}

.field label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-3);
}

.field select,
.field input[type="date"],
.field textarea {
    width: 100%;
    font: inherit;
    font-size: 0.97rem;
    color: var(--ink);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.625rem;
    transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
    resize: vertical;
}
.field textarea { min-height: 2.375rem; }
.field select:hover,
.field input[type="date"]:hover,
.field textarea:hover { border-color: var(--border-strong); }
.field select:focus,
.field input[type="date"]:focus,
.field textarea:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--cherry);
    box-shadow: 0 0 0 3px var(--cherry-soft);
}

/* ---------- combobox (author autocomplete) ---------- */

.combobox {
    position: relative;
}
.combobox__list {
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    right: 0;
    z-index: 20;
    margin: 0;
    padding: 0.25rem;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    max-height: 15rem;
    overflow-y: auto;
}
.combobox__list[hidden] { display: none; }
.combobox__item {
    padding: 0.375rem 0.625rem;
    border-radius: 4px;
    cursor: pointer;
    color: var(--ink-2);
    font-size: 0.875rem;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.combobox__item:hover,
.combobox__item.is-active {
    background: var(--cherry-soft);
    color: var(--cherry-deep);
}
.combobox__item .match {
    font-weight: 600;
    color: var(--cherry);
}
.combobox__empty {
    padding: 0.375rem 0.625rem;
    color: var(--ink-3);
    font-size: 0.8125rem;
    font-style: italic;
}

/* ---------- info card ---------- */

.card--info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.125rem;
    min-height: 0;
    padding-bottom: 1.125rem;
}

.info-block {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.info-block__head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}
.info-block__head h3 {
    font-size: 0.9375rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-2);
}
.info-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    display: inline-block;
}
.info-dot--commit { background: var(--cherry); }
.info-dot--edge   { background: var(--ink-2); }

/* dl-as-grid for label/value alignment */
.info-grid {
    display: grid;
    grid-template-columns: 9.375rem 1fr;
    gap: 0.375rem 0.875rem;
    margin: 0;
}
.info-grid--narrow {
    grid-template-columns: 11.25rem 1fr;
}
.info-grid dt {
    font-size: 0.875rem;
    color: var(--ink-3);
    font-weight: 500;
    padding-top: 0.375rem;
}
.info-grid dd {
    margin: 0;
    font-size: 0.9375rem;
    color: var(--ink);
    background: var(--surface-3);
    border-radius: var(--radius-sm);
    padding: 0.375rem 0.625rem;
    min-height: 1.75rem;
    word-break: normal;
    overflow-wrap: anywhere;
}
.info-grid dd:empty::before {
    content: "\2014";       /* em-dash placeholder */
    color: var(--muted);
}

.mono   { font-family: var(--font-mono); font-size: 0.875rem; }
.nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.break  { word-break: break-all; overflow-wrap: anywhere; }
.message {
    white-space: pre-line;
    line-height: 1.45;
    min-height: 9em;
    max-height: 16em;
    overflow: auto;
    font-size: 0.875rem;
}

/* ---------- graph area ---------- */

.graph {
    position: relative;
    background: var(--graph-surface);
    border: 1px solid var(--graph-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    min-height: 32.5rem;
    min-width: 0;
}

.canvas {
    position: absolute;
    inset: 0;
    /* very subtle cherry blush, more neutral than the old gradient */
    background:
        radial-gradient(1200px 600px at 100% 0%, rgba(185, 28, 44, 0.05) 0%, transparent 60%),
        radial-gradient(900px 500px at 0% 100%, rgba(47, 95, 177, 0.04) 0%, transparent 60%),
        var(--canvas-bg);
}

/* ---------- legend ---------- */

.legend {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 5;
    background: var(--legend-bg);
    backdrop-filter: blur(6px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 0.875rem;
    box-shadow: var(--shadow);
    min-width: 15rem;
    font-size: 0.9375rem;
    color: var(--ink-2);
}
.legend__title {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-3);
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.legend__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4375rem;
}
.legend__list li {
    display: grid;
    grid-template-columns: 1.75rem 1fr;
    align-items: center;
    color: var(--ink-2);
}
.legend__divider {
    height: 1px;
    background: var(--border);
    margin: 0.625rem 0;
}

.lg-glyph {
    display: inline-block;
    width: 1.125rem;
    height: 0.875rem;
    position: relative;
}
.lg-glyph--diamond {
    width: 0.875rem;
    height: 0.875rem;
    background: #2f5fb1;
    transform: rotate(45deg);
    border: 2px solid #1f3f73;
    border-radius: 2px;
    margin-left: 0.1875rem;
    box-shadow: 0 1px 3px rgba(31, 63, 115, 0.3);
}
.lg-glyph--dot {
    width: 1.125rem;
    height: 1.125rem;
    background: #c1273a;
    border: 2px solid #7a1320;
    border-radius: 50%;
    margin-left: 0.25rem;
    box-shadow: 0 1px 3px rgba(122, 19, 32, 0.3);
}
.lg-glyph--arrow {
    height: 0;
    width: 1.375rem;
    margin-left: 0;
    border-top-style: solid;
    border-top-width: 2px;
    align-self: center;
}
.lg-glyph--arrow::after {
    content: "";
    position: absolute;
    right: -1px;
    top: 50%;
    width: 0;
    height: 0;
    border-left: 6px solid currentColor;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transform: translateY(-50%);
}
.lg-glyph--parent   { color: #9ca3af; border-top-color: #9ca3af; }
.lg-glyph--explicit { color: #d97706; border-top-color: #d97706; }
.lg-glyph--implicit {
    color: #374151;
    border-top-color: #374151;
    border-top-style: dashed;
}

/* ---------- tooltip (preserved hooks for tooltip.js) ---------- */

.tooltip-window {
    display: none;
    position: absolute;
    background: #1f1416;
    color: #fff;
    padding: 0.375rem 0.625rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: 0.84rem;
    z-index: 1000;
    pointer-events: none;
    max-width: 15rem;
}

/* ---------- footer ---------- */

.sitefoot {
    background: var(--surface);
    border-top: 1px solid var(--border);
    color: var(--ink-2);
    font-size: 0.875rem;
}
.sitefoot__inner {
    max-width: 87.5rem;
    margin: 0 auto;
    padding: 1.125rem 1.75rem;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1.875rem;
}
.sitefoot__col { display: flex; flex-direction: column; gap: 0.25rem; }
.sitefoot__col--cite { text-align: right; max-width: 40rem; }
.sitefoot__label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-3);
    font-weight: 600;
}
.sitefoot__line { color: var(--ink-2); }
.sitefoot__line.muted { color: var(--ink-3); }
.sitefoot a { color: var(--cherry); }
.sitefoot a:hover { color: var(--cherry-deep); }

/* ---------- responsive ---------- */

@media (max-width: 960px) {
    .layout {
        grid-template-columns: 1fr;
    }
    .graph { min-height: 30rem; }
    .sitefoot__inner {
        grid-template-columns: 1fr;
    }
    .sitefoot__col--cite { text-align: left; }
}
