/*
 * Log Dog AI — Raw Tables view styles
 *
 * Scoped to .raw-view-root and its descendants. Sourced from the
 * Results Viewer v2 prototype (UI-Design/260608-design-handoff/) with all
 * colors expressed via the design tokens defined in :root (styles.css).
 *
 * Owned by Agent E (Phase 1). Loaded via <link> from static/index.html.
 */

/* ── Local semantic tokens (badge palette) ───────────────────────────
 *
 * The base token set (styles.css :root) defines only one amber pair, the
 * accent blue pair, the success teal, and surface neutrals — not enough
 * to cover all seven classification badge buckets from Style Guide §5.
 *
 * These badge-palette tokens are scoped to the raw-tables view (the only
 * place the badge classes are used). Values mirror Style Guide §5 exactly.
 * When the global token system grows semantic classification colors, swap
 * these aliases to point at them without touching the JS or badge rules.
 */
.raw-view-root {
    --badge-col-bg:     #eaf7f0;
    --badge-col-fg:     #1a7845;
    --badge-col-bd:     #70c090;

    --badge-tbl-bd:     #a0b8f8;

    --badge-lit-bg:     #e8f8f5;
    --badge-lit-fg:     #1a7868;
    --badge-lit-bd:     #70c0b8;

    --badge-sum-bg:     #f5eef8;
    --badge-sum-fg:     #8040a0;
    --badge-sum-bd:     #c088d8;

    --badge-assay-bg:   #f0f0ff;
    --badge-assay-fg:   #505090;
    --badge-assay-bd:   #b0b0e0;

    --badge-survey-bg:  #fff0f0;
    --badge-survey-fg:  #902020;
    --badge-survey-bd:  #e0a0a0;

    --badge-hdr-bd:     #e8b870;
}

/* ── Root container ─────────────────────────────────────────────────── */
.raw-view-root {
    font-family: var(--f);
    color: var(--tx);
    background: var(--s1);
}

.raw-view-empty {
    padding: 1.5rem;
    font-size: .85rem;
    color: var(--txm);
    font-style: italic;
}

/* ── Per-page accordion (.rp) ───────────────────────────────────────── */
.rp {
    border-bottom: 1px solid var(--bd);
}

.rp .rp-hdr {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem 1.5rem;
    background: var(--s1);
    border-bottom: 1px solid var(--bd);
    cursor: pointer;
    position: sticky;
    top: 0;
    z-index: 40;
}

.rp .rp-hdr:hover {
    background: var(--s2);
}

.rp .rp-pchev {
    color: var(--txm);
    display: inline-flex;
    align-items: center;
    transition: transform .15s;
    flex-shrink: 0;
}

.rp:not(.open) .rp-pchev {
    transform: rotate(-90deg);
}

.rp:not(.open) .rp-inner {
    display: none;
}

.rp .rp-ptitle {
    font-size: .85rem;
    font-weight: 600;
}

.rp .rp-pcnt {
    font-family: var(--fm);
    font-size: .63rem;
    color: var(--txd);
    margin-left: auto;
    flex-shrink: 0;
}

/* Single-column layout: the sticky source-image column and Hide/Show toggle
   have been removed in favor of per-row source links (.row-source-link in
   each .rtt row's trailing cell) that open the slide-in source panel. */
.rp .rp-inner {
    display: block;
}

.rp .rp-tables-col {
    padding: 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.rp .rp-empty {
    padding: .75rem;
    font-size: .78rem;
    font-style: italic;
    color: var(--txm);
    border: 1px dashed var(--bd);
    border-radius: var(--rs);
    text-align: center;
}

/* ── Trailing source-link column in each .rtt row ──
   Matches the .row-source-link pattern from the hole view:
   hidden by default, revealed on row hover, accent on hover/active. */
/* Raw Tables View — Style Match: Src column header + cell +
   always-visible pill (mirrors hole-view .source-col / .row-source-link). */
.rtt .rtt-src-col {
    width: 54px;
    text-align: center;
    background: var(--s2);
}

.rtt .rtt-src-cell {
    width: 54px;
    text-align: center;
    padding: .7rem .5rem !important;
    vertical-align: middle;
}

.rtt .rtt-src-cell .row-source-link {
    display: inline-flex;
    align-items: center;
    gap: .2rem;
    font-family: var(--fm);
    font-size: .66rem;
    font-weight: 400;
    color: var(--txm);
    background: var(--s2);
    border: 1px solid var(--bd);
    border-radius: 999px;
    padding: .12rem .45rem;
    cursor: pointer;
    transition: all .12s;
    white-space: nowrap;
    line-height: 1;
    /* ALWAYS VISIBLE — no opacity:0 / pointer-events:none. */
    opacity: 1;
    pointer-events: auto;
}

.rtt .rtt-src-cell .row-source-link:hover,
.rtt .rtt-src-cell .row-source-link.active {
    border-color: var(--ac);
    color: var(--ac);
    background: var(--ac2);
    opacity: 1;
}

/* ── Raw table card (.rtc) ──────────────────────────────────────────── */
.rtc {
    border: 1px solid var(--bd);
    border-radius: var(--r);
    overflow: hidden;
    background: var(--s1);
}

/* Raw Tables View — Style Match: rtc-hdr matches hole-view section meta
   strip vibe. Larger name (.82rem/600), tighter padding, full --tx. */
.rtc-hdr {
    display: flex;
    align-items: center;
    gap: .375rem;
    padding: .5rem .85rem;
    background: var(--s2);
    border-bottom: 1px solid var(--bd);
}

.rtc-name {
    font-size: .82rem;
    font-weight: 600;
    font-family: var(--fm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
    color: var(--tx);
}

.rtc-meta {
    font-family: var(--fm);
    font-size: .63rem;
    color: var(--txd);
    margin-left: auto;
    flex-shrink: 0;
}

.rtc-body {
    overflow-x: auto;
}

.rtt {
    width: 100%;
    border-collapse: collapse;
}

/* Raw Tables View — Style Match: headers + cells + zebra mirror the
   hole-view .categorized-table treatment. */
.rtt th {
    font-family: var(--fm);
    font-size: .76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--tx);
    padding: .6rem .85rem;
    border-bottom: 1px solid var(--bd);
    text-align: left;
    background: var(--s2);
    white-space: nowrap;
    position: sticky; top: 0; z-index: 2;
}

.rtt td {
    font-size: .82rem;
    padding: .7rem .85rem;
    border-bottom: 1px solid var(--bd2);
    color: var(--tx);
    vertical-align: top;
    line-height: 1.5;
    text-align: left;
}

.rtt td.v {
    color: var(--tx);
}

.rtt tr:last-child td {
    border-bottom: none;
}

/* Zebra + visible hover (matches hole-view .categorized-table). */
.rtt tbody tr:nth-child(even) td { background: #fafbfe; }
.rtt tbody tr:hover td { background: var(--ac2); }

/* ── OCR collapsible section ────────────────────────────────────────── */
.rtc-ocr {
    border-top: 1px solid var(--bd2);
}

.rtc-ocr-btn {
    width: 100%;
    text-align: left;
    padding: .4rem .625rem;
    font-size: .75rem;
    color: var(--txm);
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: .35rem;
    transition: color .15s;
}

.rtc-ocr-btn:hover {
    color: var(--tx);
}

.rtc-ocr-btn svg {
    transition: transform .15s;
}

.rtc-ocr-txt {
    display: none;
    padding: .625rem .75rem;
    margin: 0;
    font-family: var(--fm);
    font-size: .62rem;
    color: var(--txm);
    line-height: 1.65;
    background: var(--s2);
    white-space: pre-wrap;
    border-top: 1px solid var(--bd);
}

.rtc-ocr-txt.open {
    display: block;
}

/* ── Classification badges ──────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    font-family: var(--fm);
    font-size: .57rem;
    letter-spacing: .07em;
    text-transform: uppercase;
    padding: .12rem .38rem;
    border-radius: 3px;
    border: 1px solid;
    flex-shrink: 0;
}

/*
 * Badge rules consume the badge-palette tokens defined at the top of this
 * file. Per Style Guide §5: HEADER amber · COLLAR green · TABLE blue ·
 * LITHOLOGY teal · SUMMARY purple · ASSAY indigo · SURVEY rose.
 */
.badge-hdr {
    background: var(--amber2);
    color: var(--amber);
    border-color: var(--badge-hdr-bd);
}

.badge-col {
    background: var(--badge-col-bg);
    color: var(--badge-col-fg);
    border-color: var(--badge-col-bd);
}

.badge-tbl {
    background: var(--ac2);
    color: var(--ac);
    border-color: var(--badge-tbl-bd);
}

.badge-lit {
    background: var(--badge-lit-bg);
    color: var(--badge-lit-fg);
    border-color: var(--badge-lit-bd);
}

.badge-sum {
    background: var(--badge-sum-bg);
    color: var(--badge-sum-fg);
    border-color: var(--badge-sum-bd);
}

.badge-assay {
    background: var(--badge-assay-bg);
    color: var(--badge-assay-fg);
    border-color: var(--badge-assay-bd);
}

.badge-survey {
    background: var(--badge-survey-bg);
    color: var(--badge-survey-fg);
    border-color: var(--badge-survey-bd);
}

/* ── Raw View 2D pivot layout (sidebar + content) ───────────────────── */
.rv-layout {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    gap: 1rem;
    margin-top: 1rem;
    align-items: start;
}

/* ── Sidebar ────────────────────────────────────────────────────────── */
.rv-sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    border: 1px solid var(--bd);
    border-radius: 8px;
    background: var(--s1);
    padding: .5rem;
}

/* Raw Tables View — Style Match: bordered segmented control.
   Active button = solid accent fill / white text. */
.rv-mode-switcher {
    display: flex;
    gap: 2px;
    background: var(--s2);
    border: 1px solid var(--bd);
    border-radius: var(--rs);
    padding: 2px;
    margin-bottom: .5rem;
}
.rv-mode-switch {
    flex: 1;
    padding: .3rem .25rem;
    font-size: .8rem;
    font-weight: 600;
    font-family: var(--f);
    color: var(--txm);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all .12s;
}
.rv-mode-switch:hover:not(.active) {
    color: var(--tx);
}
.rv-mode-switch.active {
    background: var(--ac);
    color: #fff;
    box-shadow: 0 1px 3px rgba(59, 93, 232, .3);
}

.rv-sidebar-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-top: .25rem;
}
.rv-sidebar-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .45rem .6rem;
    font-size: .8rem;
    font-family: var(--f);
    color: var(--tx);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
    transition: background .1s, color .1s;
}
.rv-sidebar-item:hover:not(.no-data) {
    background: var(--s2);
}
/* Raw Tables View — Style Match: active sidebar item = white + ring
   (mirrors hole-view .fi-wrap.active). */
.rv-sidebar-item.active {
    background: var(--s1);
    color: var(--ac);
    font-weight: 600;
    box-shadow: 0 0 0 1px var(--bd);
    border-radius: 4px;
}
.rv-sidebar-item.no-data {
    opacity: .4;
    cursor: not-allowed;
}
.rv-sidebar-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rv-sidebar-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.4rem;
    padding: 0 .35rem;
    height: 1.1rem;
    font-family: var(--fm);
    font-size: .65rem;
    color: var(--txm);
    background: var(--s2);
    border-radius: 999px;
}
.rv-sidebar-item.active .rv-sidebar-count {
    background: var(--ac2);
    color: var(--ac);
}
.rv-sidebar-item.no-data .rv-sidebar-count {
    background: transparent;
    border: 1px solid var(--bd);
}

/* ── Content panel ──────────────────────────────────────────────────── */
.rv-content {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}
.rv-content-title {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .25rem 0 .5rem;
    border-bottom: 1px solid var(--bd);
}
.rv-content-title-lbl {
    font-size: 1rem;
    font-weight: 500;
    color: var(--tx);
}
.rv-content-title-meta {
    font-family: var(--fm);
    font-size: .7rem;
    color: var(--txm);
    letter-spacing: .04em;
}
/* ── Sub-tabs (horizontal strip; type-mode variant wraps) ──────────── */
/* Raw Tables View — Style Match: mirror hole-view .section-tab.
   Active count badge inverts to solid accent fill / white text. */
.rv-subtabs {
    display: flex;
    align-items: stretch;
    gap: 0;
    border-bottom: 1px solid var(--bd);
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    background: var(--s1);
    padding: 0 .35rem;
}
.rv-subtabs-wrap {
    overflow-x: visible;
    flex-wrap: wrap;
    row-gap: .15rem;
}
.rv-subtab {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .7rem .9rem;
    font-size: .85rem;
    font-family: var(--f);
    font-weight: 600;
    color: var(--txm);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    transition: color .12s, border-color .12s;
    white-space: nowrap;
}
.rv-subtab:hover { color: var(--tx); }
.rv-subtab.active {
    color: var(--ac);
    border-bottom-color: var(--ac);
}
.rv-subtab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    padding: 0 .42rem;
    height: 1.15rem;
    font-family: var(--fm);
    font-size: .66rem;
    font-weight: 700;
    color: var(--txm);
    background: var(--s3);
    border-radius: 999px;
}
.rv-subtab.active .rv-subtab-count {
    color: #fff;
    background: var(--ac);
}

/* ── Tables area (reuses existing .rtc / .rtt styles) ──────────────── */
.rv-tables-area {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

/* ── Empty state ───────────────────────────────────────────────────── */
.rv-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--txm);
    font-size: .85rem;
    font-style: italic;
    border: 1px dashed var(--bd);
    border-radius: 6px;
}

/* ── Narrow viewport — stack sidebar above content ──────────────────── */
@media (max-width: 720px) {
    .rv-layout {
        grid-template-columns: 1fr;
    }
    .rv-sidebar {
        position: static;
        max-height: none;
    }
}
