/* /static/css/pages/narratives.css */

:root {
    --card-border: rgba(147, 197, 253, 0.10);
    --card-shadow:
        0 16px 50px rgba(0, 0, 0, 0.34),
        inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

main.main.narratives-page {
    display: block;
    min-width: 0;
}

main.main.narratives-page > section {
    display: block;
    width: 100%;
    min-width: 0;
    margin: 0;
}

main.main.narratives-page > section + section {
    margin-top: 14px;
}

.page-hero.narratives-hero {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 20px;
    border: 1px solid rgba(147, 197, 253, 0.16);
    border-radius: 22px;
    box-shadow: var(--card-shadow);
    margin-bottom: 10px;
}

.narratives-hero .hero-main {
    min-width: 0;
}

.narratives-hero .eyebrow {
    margin: 0 0 8px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #93c5fd;
}

.narratives-hero h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.05;
    font-weight: 900;
    color: #f8fafc;
}

.narratives-hero .hero-copy {
    max-width: 760px;
    margin: 10px 0 0;
    color: #a5b4cc;
    font-size: 13px;
    line-height: 1.6;
}

.narratives-hero .hero-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.narratives-hero .hero-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: flex-end;
    align-content: flex-start;
    min-width: 260px;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.page-title {
    margin: 0;
    font-size: 18px;
    line-height: 1.15;
    font-weight: 900;
    letter-spacing: 0.02em;
    color: #f3f4f6;
}

.page-subtitle {
    margin: 8px 0 0;
    color: #95a6c2;
    font-size: 13px;
    line-height: 1.55;
    max-width: 72ch;
}

.narrative-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.15fr) minmax(300px, 0.8fr);
    gap: 14px;
    align-items: start;
    width: 100%;
    min-width: 0;
    clear: both;
}

.narrative-grid > .card {
    min-width: 0;
    width: 100%;
    align-self: start;
}

.narrative-grid + .card {
    clear: both;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.narrative-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.1fr) minmax(320px, 0.72fr);
    grid-template-areas: "drill why actions";
    gap: 16px;
    align-items: start;
    min-width: 0;
}

.narrative-grid > .card:nth-child(1) { grid-area: drill; }
.narrative-grid > .card:nth-child(2) { grid-area: why; }
.narrative-grid > .card:nth-child(3) { grid-area: actions; }

.narrative-grid > .card {
    min-width: 0;
    align-self: start;
    height: auto;
}

.stack {
    display: grid;
    gap: 14px;
}

.row,
.toolbar,
.ref-list,
.chip-list {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}

.two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.table-wrap {
    overflow: auto;
    min-width: 0;
}

.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.tiny { font-size: 11px; }
.muted { color: var(--muted); }
.mono { word-break: break-word; }

.card {
    position: relative;
    overflow: hidden;
    min-width: 0;
    border-radius: 20px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    isolation: isolate;
    margin-bottom: 10px;
}

.card::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.card-head {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    min-height: 64px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 10px;
}

.card-title {
    margin: 0;
    color: #f3f4f6;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 0.02em;
    line-height: 1.3;
}

.card-subtitle {
    margin-top: 5px;
    color: #94a3b8;
    font-size: 12px;
    line-height: 1.5;
}

.card-body {
    position: relative;
    z-index: 1;
    padding: 16px;
    min-width: 0;
    display: grid;
    gap: 14px;
}

.btn {
    appearance: none;
    min-height: 36px;
    padding: 8px 14px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.025));
    color: var(--text);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    text-decoration: none;
    border-color: rgba(96, 165, 250, 0.28);
    background: linear-gradient(180deg, rgba(96, 165, 250, 0.14), rgba(96, 165, 250, 0.06));
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.14);
}

.btn.primary {
    color: #eff6ff;
    border-color: rgba(96, 165, 250, 0.34);
    background: linear-gradient(180deg, rgba(37, 99, 235, 0.34), rgba(37, 99, 235, 0.16));
}

.metric {
    min-height: 104px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(17, 28, 51, 0.45);
}

.metric-label {
    color: #94a3b8;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    line-height: 1.4;
}

.metric-value {
    margin-top: 10px;
    color: #eef2ff;
    font-size: 34px;
    line-height: 1;
    font-weight: 900;
}

.metric-foot {
    margin-top: 10px;
    color: #8da0bf;
    font-size: 12px;
    line-height: 1.5;
}

.badge,
.trace-chip,
.ref-chip,
.json-chip,
.watch-chip,
.alert-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 26px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(6, 16, 34, 0.78);
    color: #d2dbff;
    font-size: 11px;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    max-width: 100%;
}

.badge.violet {
    color: #ddd6fe;
    border-color: rgba(167, 139, 250, 0.22);
    background: rgba(91, 33, 182, 0.18);
}

.badge.blue,
.trace-chip,
.ref-chip,
.json-chip,
.watch-chip,
.alert-chip {
    color: #bfdbfe;
    border-color: rgba(96, 165, 250, 0.20);
    background: rgba(30, 64, 175, 0.18);
}

.badge.green {
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.24);
    background: rgba(20, 83, 45, 0.24);
}

.badge.red {
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.24);
    background: rgba(127, 29, 29, 0.18);
}

.badge.amber {
    color: #fde68a;
    border-color: rgba(245, 158, 11, 0.24);
    background: rgba(120, 53, 15, 0.20);
}

.trace-chip:hover,
.ref-chip:hover,
.json-chip:hover,
.watch-chip:hover,
.alert-chip:hover {
    text-decoration: none;
    border-color: rgba(96, 165, 250, 0.32);
    background: rgba(37, 99, 235, 0.24);
}

.empty,
.narrative-item,
.summary-box,
.quote,
.map-box,
.control-group,
.progress,
.json-box {
    min-width: 0;
}

.empty,
.narrative-item,
.summary-box,
.quote {
    padding: 14px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(17, 28, 51, 0.42);
    line-height: 1.6;
}

.control-group {
    display: grid;
    gap: 8px;
}

.control-group label {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.control-group input {
    min-height: 40px;
    padding: 10px 12px;
    border-radius: 14px;
}

.progress {
    height: 8px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(17, 28, 51, 0.65);
}

.progress > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(96, 165, 250, 0.86), rgba(167, 139, 250, 0.86));
}

.map-box {
    position: relative;
    min-height: 320px;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(7, 14, 28, 0.48);
    overflow: hidden;
}

.map-node {
    position: absolute;
    display: grid;
    gap: 4px;
    min-width: 120px;
    max-width: 180px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid rgba(96, 165, 250, 0.16);
    background: rgba(17, 28, 51, 0.86);
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.18);
}

.map-node small {
    color: #9fb0c8;
    line-height: 1.4;
}

.map-line {
    position: absolute;
    height: 2px;
    background: linear-gradient(90deg, rgba(96, 165, 250, 0.18), rgba(167, 139, 250, 0.18));
    transform-origin: left center;
    box-shadow: 0 0 12px rgba(96, 165, 250, 0.10);
}

.json-box {
    margin: 0;
    padding: 14px;
    border-radius: 16px;
    color: #dbeafe;
    font-size: 12px;
    line-height: 1.6;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

details > summary.btn {
    list-style: none;
    cursor: pointer;
}

details > summary::-webkit-details-marker {
    display: none;
}

@media (max-width: 1500px) {
    .narrative-grid {
        grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
        grid-template-areas:
            "drill actions"
            "why actions";
    }
}

@media (max-width: 1250px) {
    .grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid-2,
    .two-col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 980px) {
    .page-head,
    .card-head,
    .narrative-grid {
        grid-template-columns: 1fr;
    }

    .page-head,
    .card-head {
        flex-direction: column;
        align-items: stretch;
    }

    .narrative-grid {
        grid-template-areas:
            "drill"
            "why"
            "actions";
    }
}

@media (max-width: 760px) {
    .narratives-page {
        gap: 14px;
    }

    .grid-4 {
        grid-template-columns: 1fr;
    }

    .toolbar,
    .row,
    .chip-list,
    .ref-list {
        width: 100%;
    }

    .toolbar > *,
    .row > *,
    .chip-list > *,
    .ref-list > * {
        max-width: 100%;
    }
}

@media (max-width: 620px) {
    .btn {
        width: 100%;
    }

    .toolbar,
    .row {
        display: grid;
        grid-template-columns: 1fr;
    }

    .map-node {
        max-width: 120px;
        font-size: 10px;
    }
}
.narratives-top-table {
    overflow: visible !important;
}

.narratives-top-table + .narrative-grid {
    margin-top: 20px !important;
}

.narratives-top-table::before {
    display: none !important;
}

.narratives-top-table,
.narratives-top-table .card-body {
    box-shadow: none !important;
}

/* unified header overrides */
.narratives-page {
    display: grid;
    gap: 16px;
}

.narratives-page > section {
    min-width: 0;
}

.narratives-page .page-head,
.narratives-page .unified-page-head {
    margin-bottom: 0 !important;
}

/* unified header spacing */
.narratives-page {
  gap: var(--page-gap) !important;
}

.narratives-page .page-title,
.narratives-page .page-subtitle,
.narratives-page .hero-copy {
  margin: 0 !important;
}

.narratives-page .hero-meta,
.narratives-page .page-meta {
  margin-top: var(--content-gap) !important;
}

.narratives-page .page-head,
.narratives-page .unified-page-head {
  margin-bottom: var(--page-gap) !important;
}

/* narratives spacing normalization */
.narratives-page {
  gap: var(--page-gap) !important;
}

.narratives-page > section,
.narratives-page > .card,
.narratives-page > .grid,
.narratives-page > .stack,
.narratives-page > .narrative-grid {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

.narratives-page .page-head,
.narratives-page .unified-page-head {
  gap: var(--page-gap) !important;
  margin-bottom: var(--page-gap) !important;
}

.narratives-page .page-title,
.narratives-page .page-subtitle,
.narratives-page .page-meta {
  margin: 0 !important;
}

.narratives-page .grid-4,
.narratives-page .grid-2,
.narratives-page .two-col,
.narratives-page .stack,
.narratives-page .narrative-grid {
  gap: var(--section-gap) !important;
}

.narratives-page .card {
  margin-bottom: 0 !important;
}

.narratives-page .card-head {
  margin-bottom: 0 !important;
}

.narratives-page .card-subtitle {
  margin-top: 0 !important;
}

.narratives-page .narratives-top-table + .narrative-grid {
  margin-top: 0 !important;
}
