/* Detail View Specific Styles */
#detail-view {
    display: flex;
    flex-direction: column;
    /* Use actual measured viewport height for accurate mobile browser calculations */
    height: calc(var(--actual-vh, 100vh) - var(--header-height));
    background-color: var(--bg-color); /* Override body letterbox color for content */
    box-sizing: border-box;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(0.5rem, 2vw, var(--spacing-md)) clamp(0.5rem, 2vw, var(--spacing-md)) 0;
    margin-bottom: clamp(0.5rem, 3vw, var(--spacing-lg));
    flex-shrink: 0; /* Prevent header from shrinking */
    gap: clamp(0.25rem, 1.5vw, var(--spacing-md)); /* Dynamic spacing that scales with viewport */
    flex-wrap: nowrap; /* Prevent wrapping */
    min-height: 0; /* Allow content to shrink */
}

.detail-toggle-button {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: clamp(0.25rem, 1vw, var(--spacing-sm)) clamp(0.5rem, 2vw, var(--spacing-md));
    border-radius: 8px;
    cursor: pointer;
    font-size: clamp(0.75rem, 2.5vw, var(--font-size-md));
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    white-space: nowrap; /* Prevent text wrapping */
    min-width: 0; /* Allow button to shrink */
    flex-shrink: 1; /* Allow button to shrink if needed */
}

.detail-toggle-button:hover {
    background-color: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.detail-toggle-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.detail-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    min-height: 0; /* Allow flex item to shrink */
    padding: 0;
    /* Ensure content doesn't get cut off by mobile browser UI */
    padding-bottom: max(0, env(safe-area-inset-bottom, 0px));
}

#calculator-container {
    width: 100%;
    flex: 1;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

#calculator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    border: none;
}

.description-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex item to shrink */
}

/* Toggle view states */
.detail-content.show-calculator .description-container,
.detail-content.show-notes #calculator-container {
    display: none;
}

.detail-content.show-calculator #calculator-container,
.detail-content.show-notes .description-container {
    display: flex;
}

#concept-description {
    flex: 1;
    padding: var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    resize: none;
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    line-height: 1.6;
    overflow-y: auto; /* Allow scrolling within textarea only */
    min-height: 0; /* Allow flex item to shrink */
}

#back-button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: clamp(0.25rem, 1vw, var(--spacing-sm)) clamp(0.5rem, 2vw, var(--spacing-md));
    border-radius: 8px;
    cursor: pointer;
    font-size: clamp(0.75rem, 2.5vw, var(--font-size-md));
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    white-space: nowrap; /* Prevent text wrapping */
    min-width: 0; /* Allow button to shrink */
    flex-shrink: 1; /* Allow button to shrink if needed */
}

#back-button:hover {
    background-color: #1a252f;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

#back-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Concept title responsive styling */
#concept-title {
    font-size: clamp(1rem, 4vw, var(--font-size-xl));
    font-weight: 600;
    margin: 0;
    text-align: center;
    min-width: 0; /* Allow title to shrink */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 clamp(0.25rem, 1vw, 0.5rem); /* Small padding on sides */
}

/* Title with swap button */
.title-with-swap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
    justify-content: center;
}

.swap-btn {
    background: white;
    border: 2px solid #ddd;
    border-radius: 50%;
    padding: 0.4rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.swap-btn:hover {
    background: #f8f9fa;
    border-color: #bbb;
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.swap-btn:active {
    transform: scale(0.95);
    background: #e9ecef;
}

.swap-btn .swap-icon {
    width: 1.5rem;
    height: 1.5rem;
    filter: brightness(0) saturate(100%) invert(45%) sepia(0%) saturate(0%) hue-rotate(180deg); /* Dark gray icon */
    transition: all 0.2s ease;
}

/* Responsive breakpoints for extra narrow screens */
@media (max-width: 480px) {
    .detail-header {
        padding: 0.25rem 0.5rem 0;
        margin-bottom: 0.5rem;
        gap: 0.25rem;
    }
    
    #back-button,
    .detail-toggle-button {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
        border-radius: 6px;
    }
    
    #concept-title {
        font-size: 1rem;
        padding: 0 0.25rem;
    }
}

@media (max-width: 320px) {
    .detail-header {
        padding: 0.125rem 0.25rem 0;
        gap: 0.125rem;
    }
    
    #back-button,
    .detail-toggle-button {
        padding: 0.125rem 0.375rem;
        font-size: 0.6875rem;
        border-radius: 4px;
    }
    
    #concept-title {
        font-size: 0.875rem;
        padding: 0 0.125rem;
    }
}

/* Ultra-wide screen adjustments */
@media (min-width: 1200px) {
    .detail-header {
        max-width: 1200px;
        margin-left: auto;
        margin-right: auto;
        padding-left: 2rem;
        padding-right: 2rem;
    }
}
