/* ==========================================================================
   OSDR Veggie Nutrition Dashboard — COSE design system style
   Shared CoSE (Collaborative Science Environment) theme matching the
   AstroBotany Calibration Image Database (https://dr-richard-barker.github.io/AstroBotany/)
   ========================================================================== */

:root {
    --bg: #ffffff;
    --fg: #1a2230;
    --muted: #5a6473;
    --line: #e5e9f0;
    --card: #f7f9fc;
    --card-2: #ffffff;
    --accent: #3b6ea5;   /* CoSE blue  */
    --accent2: #3fb6a8;  /* CoSE teal  */
    --danger: #c2483f;
    --warn: #b7791f;
    --ok: #2f855a;
    --rail: 280px;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 27, 43, 0.05), 0 8px 24px rgba(16, 27, 43, 0.06);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* Light / Dark Mode Override Support */
:root[data-theme="light"] {
    --bg: #ffffff; --fg: #1a2230; --muted: #5a6473; --line: #e5e9f0;
    --card: #f7f9fc; --card-2: #ffffff; --accent: #3b6ea5; --accent2: #3fb6a8;
    --danger: #c2483f; --warn: #b7791f; --ok: #2f855a; color-scheme: light;
}
:root[data-theme="dark"] {
    --bg: #0f141b; --fg: #e6ebf2; --muted: #9aa6b6; --line: #232c39;
    --card: #161d27; --card-2: #1b2430; --accent: #6ea3d8; --accent2: #54c9ba;
    --danger: #e0736a; --warn: #d9a441; --ok: #56b98a; color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f141b;
        --fg: #e6ebf2;
        --muted: #9aa6b6;
        --line: #232c39;
        --card: #161d27;
        --card-2: #1b2430;
        --accent: #6ea3d8;
        --accent2: #54c9ba;
        --danger: #e0736a;
        --warn: #d9a441;
        --ok: #56b98a;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    }
}

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

body {
    background-color: var(--bg);
    color: var(--fg);
    font-family: var(--font);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.2s, color 0.2s;
}

a {
    color: var(--accent);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* App Flex Shell */
.app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Rail */
.rail {
    width: var(--rail);
    flex-shrink: 0;
    background: var(--card);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.rail-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 20px 20px 16px;
}
.rail-brand img {
    height: 34px;
    width: 34px;
    border-radius: 8px;
    display: block;
}
.rail-brand .t1 {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}
.rail-brand .t2 {
    font: 600 0.65rem/1 var(--mono);
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 3px;
}
.rail nav {
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

/* Sidebar buttons mapping .tab-btn */
.navbtn {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: 9px;
    border: 0;
    cursor: pointer;
    background: transparent;
    color: var(--muted);
    text-align: left;
    width: 100%;
    font: 500 0.9rem/1.2 var(--font);
    transition: background 0.15s, color 0.15s;
}
.navbtn:hover {
    background: color-mix(in srgb, var(--accent) 9%, transparent);
    color: var(--fg);
}
.navbtn.active {
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    color: var(--accent);
    font-weight: 600;
}
.navbtn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke-width: 2px;
}

.rail-tools {
    padding: 12px;
    border-top: 1px solid var(--line);
}
.rail-tools-h {
    display: flex;
    align-items: center;
    gap: 5px;
    font: 700 0.62rem/1 var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
    padding: 4px 12px 8px;
}
.tool-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 9px;
    color: var(--fg);
    text-decoration: none;
    font: 500 0.86rem/1.2 var(--font);
    cursor: pointer;
    transition: background 0.15s;
}
.tool-link:hover {
    background: color-mix(in srgb, var(--accent2) 12%, transparent);
    text-decoration: none;
}
.tool-link svg {
    color: var(--accent2);
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}
.tool-link .ext {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.75rem;
}

/* Main Content Area */
.main-content {
    flex: 1;
    padding: 2rem 2.5rem;
    overflow-y: auto;
    max-width: 1440px;
}

/* Tab Panels */
.tab-panel {
    display: none;
}
.tab-panel.active {
    display: block;
}

/* Grid Layouts */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 1.5rem;
}
.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-4 { margin-bottom: 1.5rem; }
.hidden { display: none !important; }

h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--fg);
    margin-bottom: 0.75rem;
}
h3 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--fg);
    margin-bottom: 0.25rem;
}
h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--fg);
}
p {
    color: var(--muted);
    margin-bottom: 1rem;
    font-size: 0.92rem;
}

/* Hero card */
.hero {
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 12%, var(--bg)), var(--card));
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    margin-bottom: 1.5rem;
}
.hero h2 {
    color: var(--accent);
}

/* Cards style */
.card {
    background-color: var(--card-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.stat-card {
    text-align: center;
    border-top: 4px solid var(--warn);
}
.stat-card h2 {
    font-size: 2.75rem;
    color: var(--accent);
    margin-bottom: 0.25rem;
}
.stat-card p {
    font-weight: 600;
    font-size: 0.9rem;
}

/* Plot and Chart Containers */
.plot-card {
    min-height: 520px;
}
.plot-container {
    position: relative;
    width: 100%;
    height: 420px;
    min-height: 420px;
    flex: 1;
    overflow: hidden;
}
#pca-plot {
    width: 100%;
    height: 100%;
}
.chart-wrapper {
    position: relative;
    width: 100%;
    height: 420px;
    min-height: 420px;
    flex: 1;
}

/* Buttons style */
.btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}
.btn-primary {
    background-color: var(--accent);
    color: #fff;
}
.btn-primary:hover {
    background-color: color-mix(in srgb, var(--accent) 85%, #000);
    text-decoration: none;
}
.btn-secondary {
    background-color: var(--accent2);
    color: #fff;
}
.btn-secondary:hover {
    background-color: color-mix(in srgb, var(--accent2) 85%, #000);
    text-decoration: none;
}
.btn-small {
    padding: 4px 10px;
    font-size: 0.8rem;
    background-color: var(--card);
    color: var(--fg);
    border: 1px solid var(--line);
}
.btn-small.active {
    background-color: var(--accent2);
    color: #fff;
    border-color: var(--accent2);
}

/* Controls Bar */
.controls-bar {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}
.control-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.875rem;
    font-weight: 600;
}
select {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--fg);
    font-size: 0.875rem;
    outline: none;
    cursor: pointer;
}

/* Tables & Table Container */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    margin-top: 0.5rem;
}
.stats-table-container {
    max-height: 380px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.stats-table-container table {
    margin-top: 0;
}
.stats-table-container thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background-color: var(--card);
    box-shadow: 0 1px 0 var(--line);
}
.data-table {
    width: 100%;
    min-width: 480px;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.data-table th, .data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.data-table th {
    background-color: var(--card);
    font-weight: 600;
    color: var(--fg);
}
.data-table tr:hover td {
    background-color: color-mix(in srgb, var(--accent) 4%, transparent);
}

/* Metrics Column & Cards */
.metrics-column {
    display: flex;
    flex-direction: column;
}
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-top: 0.5rem;
}
.metric-card {
    background-color: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    text-align: center;
}
.metric-num {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
}
.metric-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 4px;
}
.highlight-metric {
    color: var(--ok);
    font-weight: 700;
}

/* Badges & Status */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.4;
}
.badge-sig {
    background-color: rgba(47, 133, 90, 0.15);
    color: var(--ok);
}
.badge-nonsig {
    background-color: rgba(194, 72, 63, 0.12);
    color: var(--danger);
}
.crop-badge {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
}
.crop-lettuce { background-color: rgba(59, 110, 165, 0.15); color: var(--accent); }
.crop-mizuna { background-color: rgba(63, 182, 168, 0.18); color: var(--accent2); }

.cond-badge {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
}
.cond-flight { background-color: rgba(212, 175, 55, 0.18); color: var(--warn); }
.cond-ground { background-color: rgba(90, 100, 115, 0.15); color: var(--muted); }
.cond-withdrawn { background-color: rgba(194, 72, 63, 0.14); color: var(--danger); }

/* Marks a figure that has been withdrawn rather than silently removed, so a
   reader who saw the earlier number learns what happened to it. Deliberately
   quiet: it is a correction, not an alarm. */
.data-notice {
    border-left: 3px solid var(--danger);
    background-color: var(--card);
    border-radius: 0 8px 8px 0;
    padding: 12px 16px;
    font-size: 0.9rem;
    color: var(--muted);
}
.data-notice p { margin: 0 0 8px; }
.data-notice p:last-child { margin-bottom: 0; }
.data-notice strong { color: var(--fg); }
.data-notice code {
    font-size: 0.85em;
    padding: 1px 4px;
    border-radius: 4px;
    background-color: rgba(90, 100, 115, 0.12);
}

.sig-yes {
    color: var(--ok);
    font-weight: 600;
}
.sig-no {
    color: var(--danger);
    font-weight: 600;
}
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 5px;
}
.sig-yes .status-dot { background-color: var(--ok); }
.sig-no .status-dot { background-color: var(--danger); }

/* Gallery & Lightbox */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
}
.gallery-item {
    cursor: pointer;
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
    border: 2px solid transparent;
    box-shadow: var(--shadow);
    transition: transform 0.2s, border-color 0.2s;
}
.gallery-item:hover {
    border-color: var(--accent2);
    transform: translateY(-2px);
}
.gallery-item img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
}
.gallery-meta {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: rgba(16, 27, 43, 0.85);
    color: #fff;
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
.modal {
    display: none;
    position: fixed;
    z-index: 1100;
    left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(10, 15, 23, 0.95);
    backdrop-filter: blur(4px);
}
.modal-content {
    position: relative;
    margin: 4% auto;
    width: 85%;
    max-width: 850px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border-radius: var(--radius);
    overflow: hidden;
}
.modal-content img {
    width: 100%;
    height: auto;
    display: block;
    max-height: 70vh;
    object-fit: contain;
    background: #000;
}
.close-modal {
    position: absolute;
    top: 20px;
    right: 25px;
    color: #fff;
    font-size: 36px;
    font-weight: 300;
    cursor: pointer;
    z-index: 1200;
}
.close-modal:hover {
    color: var(--accent2);
}
.metadata-overlay {
    background: var(--card-2);
    color: var(--fg);
    padding: 1.25rem;
    border-top: 1px solid var(--line);
}
.metadata-overlay h3 {
    margin-bottom: 0.5rem;
    color: var(--accent);
}

/* Citation Blocks */
.citation-block {
    background: var(--card);
    padding: 1.25rem;
    border-radius: 8px;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 0.8rem;
    border: 1px solid var(--line);
    color: var(--fg);
    margin-top: 0.75rem;
}

/* Scrollbars styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg);
}
::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* Mobile & Tablet Responsiveness */
@media (max-width: 900px) {
    .app {
        flex-direction: column;
    }
    .rail {
        width: 100%;
        height: auto;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }
    .rail nav {
        flex-direction: row;
        overflow-x: auto;
    }
    .navbtn {
        white-space: nowrap;
    }
    .main-content {
        padding: 1.25rem;
    }
    .grid-2 {
        grid-template-columns: 1fr;
    }
}
