/* Calculator Layout */
.calculator h1 {
    font-size: 1.5rem;
    line-height: 1.4;
    color: var(--text-color);
    margin-bottom: 2rem;
    font-weight: 600;
    max-width: 800px;
}

.calculator-widget {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    background-color: var(--white);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.calculator-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
    align-items: start;
}

/* Timeline Section */
.timeline-section {
    background-color: var(--bg-light);
    padding: 1.5rem;
    border-radius: 10px;
    position: relative;
    z-index: 1;
}

.substance-timeline {
    height: 400px;
    margin-bottom: 1rem;
    position: relative;
    background-color: var(--white);
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.substance-timeline::before {
    content: 'Past';
    position: absolute;
    left: 1rem;
    top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.substance-timeline::after {
    content: 'Future';
    position: absolute;
    right: 1rem;
    top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Timeline Info */
.timeline-info {
    background-color: var(--white);
    padding: 1rem;
    border-radius: 8px;
    margin: 1rem 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.timeline-substance-info {
    background-color: var(--bg-light);
    padding: 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.timeline-substance-info:last-child {
    margin-bottom: 0;
}

.timeline-substance-info h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
    color: var(--text-color);
    text-transform: capitalize;
}

.timeline-phases {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.phase {
    background-color: var(--white);
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.9rem;
    color: var(--text-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.metabolism-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
    margin: 0.5rem 0;
    padding: 0.5rem;
    background-color: var(--white);
    border-radius: 4px;
    border-left: 3px solid var(--primary-color);
}

.detection-window {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    padding: 0.3rem 0.6rem;
    background-color: var(--white);
    border-radius: 4px;
    display: inline-block;
}

/* Controls Section */
.controls-section {
    position: sticky;
    top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    z-index: 2;
    background-color: var(--white);
    padding: 1rem;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Add/Save Substance Buttons */
.btn-add-substance {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 8px;
    background-color: var(--primary-color);
    color: var(--white);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin: 0;
    position: relative;
    z-index: 3;
}

.btn-add-substance:hover {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
}

/* Selection Menu */
.selection-menu {
    background-color: var(--white);
    padding: 1.5rem;
    border-radius: 10px;
    margin-top: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 2000px;
    opacity: 1;
    overflow: hidden;
    transform: translateY(0);
    visibility: visible;
    position: relative;
    z-index: 2;
}

.selection-menu.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin: 0;
    opacity: 0;
    transform: translateY(-10px);
    visibility: hidden;
}

.selection-menu > div {
    margin-bottom: 2rem;
}

.selection-menu > div:last-child {
    margin-bottom: 0;
}

.selection-menu h3 {
    margin-bottom: 1rem;
    color: var(--text-color);
    font-size: 1.1rem;
}

/* Step Transitions */
.step {
    display: none;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    overflow: hidden;
    max-height: 0;
}

.step.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
    max-height: 2000px;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* Dosage Selection */
.dosage-categories {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.category {
    background-color: var(--bg-light);
    padding: 1rem;
    border-radius: 8px;
    transition: all 0.3s ease;
    opacity: 1;
    max-height: 500px;
    overflow: hidden;
}

.category.hidden {
    opacity: 0;
    max-height: 0;
    padding: 0;
    margin: 0;
    pointer-events: none;
}

.category h4 {
    margin: 0 0 1rem 0;
    color: var(--text-color);
    font-size: 1rem;
}

.dosage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
}

.dosage-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background-color: var(--white);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.dosage-btn i {
    font-size: 1.5rem;
    color: var(--text-muted);
    transition: color 0.3s ease;
}

.dosage-btn span {
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
}

.dosage-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.dosage-btn:hover i {
    color: var(--primary-color);
}

.dosage-btn.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--white);
}

.dosage-btn.active i {
    color: var(--white);
}

/* Substance Grid */
.substance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.substance-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background-color: var(--white);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.substance-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.substance-btn.active {
    background-color: var(--primary-color);
    color: var(--white);
    border-color: var(--primary-color);
}

/* Time Selection */
.time-slider-container {
    padding: 0 1rem;
    margin: 1.5rem 0;
}

input[type="range"] {
    width: 100%;
    margin: 1rem 0;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.time-labels {
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Add to Timeline Button */
.btn-add {
    width: 100%;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    background-color: var(--accent-color);
    color: var(--white);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 1rem;
}

.btn-add:hover {
    background-color: var(--accent-dark);
    transform: translateY(-2px);
}

/* Results */
.calculator-result {
    padding: 1.5rem;
    border-radius: 10px;
    background-color: var(--white);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    margin-top: 1.5rem;
}

.calculator-result.show {
    opacity: 1;
    transform: translateY(0);
}

.result-safe {
    border-left: 4px solid #28a745;
}

.result-warning {
    border-left: 4px solid #ffc107;
}

.result-danger {
    border-left: 4px solid #dc3545;
}

.result-message {
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--text-color);
}

/* Risk Indicator */
.risk-indicator {
    margin: 1.5rem 0;
}

.risk-bar {
    height: 20px;
    background-color: var(--bg-light);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.risk-bar-fill {
    height: 100%;
    background-color: var(--primary-color);
    transition: width 0.5s ease;
    background-image: linear-gradient(
        45deg,
        rgba(255,255,255,0.15) 25%,
        transparent 25%,
        transparent 50%,
        rgba(255,255,255,0.15) 50%,
        rgba(255,255,255,0.15) 75%,
        transparent 75%,
        transparent
    );
    background-size: 1rem 1rem;
    animation: progress-bar-stripes 1s linear infinite;
}

@keyframes progress-bar-stripes {
    from { background-position: 1rem 0; }
    to { background-position: 0 0; }
}

.risk-level {
    display: block;
    margin-top: 0.5rem;
    text-align: right;
    font-weight: 500;
    color: var(--text-color);
}

/* Result Advice */
.result-advice {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background-color: var(--bg-light);
    border-radius: 8px;
}

.result-advice h4 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.result-advice ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.result-advice li {
    margin-bottom: 0.8rem;
    padding-left: 1.5rem;
    position: relative;
}

.result-advice li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: var(--accent-color);
}

/* Emergency Warning */
.emergency-warning {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background-color: var(--warning-bg);
    border-radius: 8px;
    border-left: 4px solid var(--warning-color);
}

.emergency-warning ul {
    list-style: none;
    margin: 1rem 0;
    padding: 0;
}

.emergency-warning li {
    margin-bottom: 0.8rem;
    padding-left: 1.5rem;
    position: relative;
}

.emergency-warning li::before {
    content: '⚠️';
    position: absolute;
    left: 0;
}

/* Interaction Warning */
.interaction-warning {
    margin: 1.5rem 0;
    padding: 1.5rem;
    background-color: #f8d7da;
    border-radius: 8px;
    border-left: 4px solid #dc3545;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.interaction-warning.show {
    opacity: 1;
    transform: translateY(0);
}

.interaction-warning h4 {
    color: var(--warning-color);
    margin-bottom: 1rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .calculator-layout {
        grid-template-columns: 1fr;
    }

    .controls-section {
        position: static;
    }

    .timeline-phases {
        flex-wrap: wrap;
    }

    .dosage-categories {
        gap: 1rem;
    }

    .dosage-grid {
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    }
}

@media (max-width: 768px) {
    .calculator h1 {
        font-size: 1.3rem;
        margin-bottom: 1.5rem;
    }

    .calculator-widget {
        padding: 1rem;
    }

    .substance-timeline {
        height: 300px;
    }

    .dosage-btn,
    .substance-btn {
        padding: 0.75rem;
        font-size: 0.8rem;
    }

    .dosage-btn i {
        font-size: 1.2rem;
    }

    .timeline-phases {
        flex-direction: column;
        gap: 0.5rem;
    }

    .phase {
        width: 100%;
    }
}

/* Accessibility Improvements */
.calculator-widget button:focus,
.calculator-widget input:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.calculator-widget input[type="range"]:focus {
    outline: none;
}

.calculator-widget *[role="alert"] {
    border-left: 4px solid currentColor;
}

/* Info Button */
.info-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem;
    margin-left: 0.5rem;
    transition: color 0.3s ease;
}

.info-btn:hover {
    color: var(--primary-color);
}

/* Tooltip */
.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip .tooltip-text {
    visibility: hidden;
    width: 200px;
    background-color: var(--text-color);
    color: var(--white);
    text-align: center;
    border-radius: 6px;
    padding: 0.5rem;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.85rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Enhanced Features */

/* Confidence Interval Styling */
.confidence-area {
    opacity: 0.15;
    pointer-events: none;
}

/* Phase Indicators */
.phase-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: rgba(255, 255, 255, 0.2);
    pointer-events: none;
}

.phase-label {
    position: absolute;
    top: 10px;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: var(--text-muted);
    background-color: rgba(255, 255, 255, 0.9);
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

/* Enhanced Risk Zone */
.risk-zone {
    background: repeating-linear-gradient(
        45deg,
        rgba(255, 0, 0, 0.1),
        rgba(255, 0, 0, 0.1) 10px,
        rgba(255, 0, 0, 0.15) 10px,
        rgba(255, 0, 0, 0.15) 20px
    );
    border-radius: 4px;
    pointer-events: none;
}

/* Chart Tooltip Enhancements */
.chart-tooltip {
    background-color: rgba(0, 0, 0, 0.9);
    color: var(--white);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    z-index: 1000;
    max-width: 250px;
}

.chart-tooltip-header {
    font-weight: bold;
    margin-bottom: 4px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.chart-tooltip-body {
    font-size: 0.85rem;
    line-height: 1.4;
}

.chart-tooltip-warning {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffc107;
}
