/*
    styles.css: Dark mode styles for Harm Reduction Protocols Dashboard.
    Handles: transitions, expandable items, scrollbar, dark chart containers.
    Design: Sharp-cornered, high-contrast, OKLCH color palette.
*/

/* ===== CSS Custom Properties ===== */
:root {
    --accent-color: #78716c;
}

/* ===== Animated Background ===== */
html {
    min-height: 100%;
    background: linear-gradient(
        to bottom,
        oklch(22% 0.07 270) 0%,
        oklch(16% 0.05 265) 20%,
        oklch(10% 0.03 260) 50%,
        oklch(5% 0.015 255) 75%,
        oklch(2% 0.005 250) 100%
    );
    background-size: 100% 200%;
    animation: bgShift 30s ease-in-out infinite alternate;
    position: relative;
}

/* Subtle color accent overlay: fades in when a substance is selected */
html::before {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at 50% 10%, var(--accent-color) 0%, transparent 65%);
    opacity: 0;
    transition: opacity 1.8s ease;
    pointer-events: none;
    z-index: 0;
}

html.accent-active::before {
    opacity: 0.13;
}

@keyframes bgShift {
    0%   { background-position: 0% 0%; }
    100% { background-position: 0% 100%; }
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: transparent;
    position: relative;
    z-index: 1;
}

/* ===== Transitions ===== */
.card-transition {
    transition: all 0.3s ease-in-out;
}

/* ===== Expandable Detail ===== */
.expandable-detail {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease-in-out, opacity 0.3s ease-in-out;
    opacity: 0;
}

.expandable-detail.open {
    max-height: 2000px;
    opacity: 1;
}

/* ===== Scrollbar (Dark) ===== */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: oklch(7% 0.02 25);
}

::-webkit-scrollbar-thumb {
    background: oklch(25% 0.01 90);
}

::-webkit-scrollbar-thumb:hover {
    background: oklch(35% 0.01 90);
}

/* ===== Chart Container ===== */
.chart-container {
    position: relative;
    width: 100%;
}

/* ===== Focus visibility (keyboard): WCAG 2.4.7 ===== */
:focus-visible {
    outline: 2px solid #f5f5f4 !important;
    outline-offset: 2px;
    border-radius: 4px;
}
/* Suppress the ring for pointer/mouse focus only, keep it for keyboard */
:focus:not(:focus-visible) {
    outline: none;
}

/* ===== Disclaimer Banner ===== */
.disclaimer-banner {
    background: rgba(34, 197, 94, 0.08);
    border-bottom: 1px solid rgba(34, 197, 94, 0.2);
}

/* ===== Selection ===== */
::selection {
    background: rgba(255, 255, 255, 0.1);
}

/* ===== Dosing Panel: Route Buttons ===== */
.route-btn {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.6);
    padding: 0.5rem 1rem;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 700;
    border-width: 2px;
    border-style: solid;
    cursor: pointer;
    transition: all 0.12s ease;
    letter-spacing: 0.02em;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45);
    transform: translateY(0);
}

.route-btn:hover {
    filter: brightness(1.35);
    opacity: 1 !important;
}

.route-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

/* ===== Dosing Panel: Tier Buttons ===== */
.tier-btn {
    background: var(--tier-bg, rgba(255, 255, 255, 0.04));
    border-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    outline: none;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45);
    transform: translateY(0);
    transition: all 0.12s ease;
}

.tier-btn:hover {
    filter: brightness(1.35);
    opacity: 1 !important;
}

.tier-btn:active {
    transform: translateY(3px) !important;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4) !important;
}

/* ===== Timeline Legend ===== */
#timeline-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

#timeline-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 11px;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

#timeline-legend .legend-swatch {
    display: inline-block;
    width: 8px;
    height: 8px;
    flex-shrink: 0;
}

/* ===== Cards: Softly rounded ===== */
.section-card,
#dosing-card,
#active-substance-header,
#emergency-flags {
    border-radius: 12px;
}

/* ===== Substance Nav Buttons ===== */
#substance-nav button {
    letter-spacing: 0.01em;
}

/* ===== Active nav button: sweep + pulse ===== */
.nav-btn-active {
    position: relative;
    overflow: hidden;
    animation: navBtnPulse 3s ease-in-out infinite;
}

.nav-btn-active::after {
    content: '';
    position: absolute;
    top: 0;
    left: -70%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: navBtnSweep 3s ease-in-out infinite;
    pointer-events: none;
}

@keyframes navBtnSweep {
    0%   { left: -70%; opacity: 0; }
    15%  { opacity: 1; }
    85%  { opacity: 1; }
    100% { left: 130%; opacity: 0; }
}

@keyframes navBtnPulse {
    0%, 100% { filter: brightness(1); }
    50%       { filter: brightness(1.15); }
}

/* ===== Drug Combinations ===== */
.combo-group-header {
    font-size: 10px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.combo-group-header:first-child {
    margin-top: 0;
}

.combo-item {
    padding: 0.625rem 0.75rem;
    margin-bottom: 0.25rem;
    transition: background 0.2s;
}

.combo-item:hover {
    filter: brightness(1.15);
}

.combo-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, monospace;
}

/* ===== Tabs: coloured, distinct active state ===== */
.tab-btn { cursor: pointer; }
.tab-btn:hover { filter: brightness(1.18); }

/* ===== Tab Slide Animations ===== */
#tab-folder-body {
    overflow: hidden;
}

@keyframes tabSlideInRight {
    from { transform: translateX(40px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes tabSlideInLeft {
    from { transform: translateX(-40px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.tab-slide-in-right {
    animation: tabSlideInRight 0.22s ease-out forwards;
}

.tab-slide-in-left {
    animation: tabSlideInLeft 0.22s ease-out forwards;
}

/* ===== Utilities ===== */
.hide-scrollbar::-webkit-scrollbar {
    display: none;
}
.hide-scrollbar {
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

/* ===== Emergency (button-only; lives inside the disclaimer banner) ===== */
.emergency-details {
    margin-top: 0.5rem;
}
.emergency-details > summary {
    display: inline-block;
    cursor: pointer;
    list-style: none;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.45);
    border-radius: 8px;
    padding: 0.3rem 0.7rem;
    transition: background 0.15s ease, color 0.15s ease;
}
.emergency-details > summary::-webkit-details-marker { display: none; }
.emergency-details > summary::marker { content: ''; }
.emergency-details > summary:hover {
    background: rgba(239, 68, 68, 0.16);
    color: #fecaca;
}
.emergency-details[open] > summary {
    margin-bottom: 0.6rem;
}
.emergency-panel {
    max-width: 46rem;
    margin: 0 auto;
    text-align: left;
    background: rgba(239, 68, 68, 0.06);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 10px;
    padding: 0.85rem 1rem;
}
.emergency-panel .ep-line {
    font-size: 0.8rem;
    line-height: 1.5;
    color: #d1d5db;
    margin-bottom: 0.5rem;
}
.emergency-panel .ep-line:last-of-type { margin-bottom: 0.35rem; }
.emergency-panel .ep-line strong { color: #f3f4f6; }
.emergency-panel .ep-source {
    font-size: 0.68rem;
    color: #9ca3af;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.emergency-panel .ep-source:hover { color: #d1d5db; }
.emergency-call {
    color: #fca5a5;
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 2px;
    white-space: nowrap;
}
.emergency-call:hover { color: #fecaca; }

/* ===== WCAG contrast lifts (AA on #1a1a19 cards) ===== */
.expandable-detail p { color: #9ca3af; }            /* detail text: gray-500 -> gray-400 (~6.9:1) */
.expandable-detail a { font-size: 11px; opacity: 0.85; }
.expandable-detail a:hover { opacity: 1; }

/* ===== Dangerous-combinations chips (surfaced above tabs) ===== */
.danger-combo-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 12px;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border: 1px solid;
    border-radius: 8px;
    white-space: nowrap;
}

/* ===== Larger tap target for [+]/[-] toggles (WCAG 2.5.8) ===== */
.expand-toggle {
    display: inline-block;
    padding: 2px 6px;
    line-height: 1;
    border-radius: 4px;
    vertical-align: baseline;
}

/* ===== Reduced motion (WCAG 2.2.2 / 2.3.3) ===== */
@media (prefers-reduced-motion: reduce) {
    html { animation: none !important; }
    .nav-btn-active { animation: none !important; }
    .nav-btn-active::after { display: none !important; }
    .tab-slide-in-right,
    .tab-slide-in-left { animation: none !important; }
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===== Risk Profile: provenance info button + panel ===== */
.risk-info-btn {
    flex-shrink: 0;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.7);
    font-family: Georgia, 'Times New Roman', serif;
    font-style: italic;
    font-weight: 700;
    font-size: 0.8rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s ease;
}

.risk-info-btn:hover {
    border-color: rgba(255, 255, 255, 0.75);
    background: rgba(255, 255, 255, 0.12);
    color: #f5f5f4;
}

.risk-info-btn[aria-expanded="true"] {
    border-color: var(--accent-color);
    background: var(--accent-color);
    color: #12120f;
}

.risk-info-inline {
    color: #9ca3af;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    font-style: normal;
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
}

.risk-info-inline:hover {
    color: #e5e7eb;
}

.risk-info-panel {
    margin-bottom: 1.25rem;
    padding: 0.9rem 1rem;
    border-radius: 10px;
    background: #151514;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-left: 3px solid var(--accent-color);
    font-size: 0.75rem;
    line-height: 1.6;
    color: #9ca3af;
}

.risk-info-panel p {
    margin-bottom: 0.6rem;
}

.risk-info-panel p:last-child {
    margin-bottom: 0;
}

.risk-info-panel .rip-lead {
    color: #e5e7eb;
    font-weight: 600;
}

.risk-info-panel strong {
    color: #d1d5db;
}

.risk-info-panel .rip-axis {
    color: #e5e7eb;
}

.risk-info-panel .rip-axes {
    margin: 0;
    padding: 0;
    list-style: none;
}

.risk-info-panel .rip-axes li {
    margin-top: 0.25rem;
}

.risk-info-panel .rip-foot {
    color: #6b7280;
    font-style: italic;
}

.risk-info-panel a {
    color: #d1d5db;
    text-decoration: underline;
    text-underline-offset: 2px;
}
