/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 10px;
    line-height: 1.6;
}

/* Container responsive height management */
.container {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    overflow: hidden;
    cursor: help;
    /* Dynamic height based on viewport */
    height: 450px;
    overflow-y: auto;
}

/* Check if running in new tab vs iframe */
@media (min-height: 600px) {
    .container {
        height: 90vh;
        max-height: 800px;
    }
}

/* Section styling */
.section {
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
    transition: all 0.3s ease;
}

.section:last-child {
    border-bottom: none;
}

.section:hover {
    background-color: #f8f9fa;
}

.section-header {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    gap: 10px;
}

.section-header h3 {
    color: #2c3e50;
    font-size: 1.1em;
    font-weight: 600;
}

.icon {
    font-size: 1.2em;
    width: 24px;
    text-align: center;
}

/* Beginning section styling */
.beginning-section {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
}

.balance-display {
    text-align: center;
    padding: 15px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.balance-label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 8px;
}

.balance-amount {
    font-size: 1.8em;
    font-weight: bold;
    color: #1976d2;
}

.fixed-amount {
    position: relative;
}

.fixed-amount::after {
    content: " (Fixed)";
    font-size: 0.5em;
    color: #666;
    font-weight: normal;
}

/* Input section styling */
.input-section {
    background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%);
}

.input-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

@media (max-width: 600px) {
    .input-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-weight: 600;
    color: #4a148c;
    font-size: 0.9em;
}

.dropdown {
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1em;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 44px; /* Touch-friendly minimum */
}

.dropdown:hover {
    border-color: #9c27b0;
    box-shadow: 0 2px 8px rgba(156, 39, 176, 0.2);
}

.dropdown:focus {
    outline: none;
    border-color: #9c27b0;
    box-shadow: 0 0 0 3px rgba(156, 39, 176, 0.1);
}

/* Calculation display */
.calculation-display {
    background: white;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-top: 15px;
}

.formula-title {
    font-weight: 600;
    color: #4a148c;
    margin-bottom: 10px;
    font-size: 0.9em;
}

.formula {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 1.2em;
    font-weight: 600;
}

.formula-part {
    background: #e8f5e8;
    padding: 8px 12px;
    border-radius: 6px;
    color: #2e7d32;
    min-width: 80px;
    text-align: center;
}

.operator {
    color: #666;
    font-size: 1.1em;
}

.formula-result {
    background: #fff3e0;
    padding: 8px 12px;
    border-radius: 6px;
    color: #f57c00;
    font-weight: bold;
    min-width: 100px;
    text-align: center;
}

/* Results section styling */
.results-section {
    background: linear-gradient(135deg, #e8f5e8 0%, #c8e6c9 100%);
}

.results-content {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.comparison-display {
    margin-bottom: 20px;
}

.comparison-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

.comparison-row:last-child {
    border-bottom: none;
}

.difference-row {
    border-top: 2px solid #ddd;
    margin-top: 10px;
    padding-top: 15px;
    font-weight: bold;
}

.comparison-row .label {
    color: #666;
    font-weight: 500;
}

.comparison-row .value {
    font-weight: bold;
    color: #2c3e50;
    font-size: 1.1em;
}

/* Modified styles for horizontal working calculation display */
.working-calculation {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 20px;
    margin: 20px 0;
    border: 2px solid #dee2e6;
}

.working-title {
    font-weight: 600;
    color: #495057;
    margin-bottom: 20px;
    font-size: 1em;
    text-align: center;
}

.working-formula-horizontal {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.working-horizontal-line {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    background: white;
    padding: 20px;
    border-radius: 10px;
    border: 2px solid #e9ecef;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.working-amount {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    min-width: 120px;
}

.working-value {
    font-weight: bold;
    color: #2c3e50;
    font-size: 1.3em;
    margin-bottom: 8px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.working-label {
    color: #495057;
    font-weight: 500;
    font-size: 0.9em;
    line-height: 1.2;
}

.working-operator {
    font-size: 2em;
    font-weight: bold;
    color: #6c757d;
    margin: 0 10px;
    display: flex;
    align-items: center;
    height: 60px;
}

/* Added styles for negative amounts in brackets */
.negative-amount {
    color: #dc3545;
}

.arrow-indicator {
    text-align: center;
    margin: 15px 0 10px 0;
}

.arrow {
    font-size: 2em;
    color: #6c757d;
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-5px);
    }
    60% {
        transform: translateY(-3px);
    }
}

.result-indication {
    text-align: center;
    padding: 15px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1.1em;
    margin-top: 10px;
}

.result-indication.impairment-loss {
    background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
    color: #d32f2f;
    border: 2px solid #f44336;
}

.result-indication.reversal {
    background: linear-gradient(135deg, #e8f5e8 0%, #c8e6c9 100%);
    color: #388e3c;
    border: 2px solid #4caf50;
}

.result-indication.neutral {
    background: linear-gradient(135deg, #f5f5f5 0%, #eeeeee 100%);
    color: #666;
    border: 2px solid #9e9e9e;
}

/* Conclusion styling */
.conclusion {
    text-align: center;
    padding: 20px;
    border-radius: 10px;
    margin-top: 15px;
    transition: all 0.3s ease;
}

.conclusion.impairment-loss {
    background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
    border: 2px solid #f44336;
}

.conclusion.reversal {
    background: linear-gradient(135deg, #e8f5e8 0%, #c8e6c9 100%);
    border: 2px solid #4caf50;
}

.conclusion.neutral {
    background: linear-gradient(135deg, #f5f5f5 0%, #eeeeee 100%);
    border: 2px solid #9e9e9e;
}

.conclusion-text {
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 10px;
}

.conclusion.impairment-loss .conclusion-text {
    color: #d32f2f;
}

.conclusion.reversal .conclusion-text {
    color: #388e3c;
}

.conclusion.neutral .conclusion-text {
    color: #666;
}

/* Action section */
.action-section {
    padding: 15px 20px;
    text-align: center;
    background: #f8f9fa;
}

.reset-btn {
    background: linear-gradient(135deg, #ff7043 0%, #ff5722 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 44px;
    box-shadow: 0 4px 12px rgba(255, 87, 34, 0.3);
}

.reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 87, 34, 0.4);
}

.reset-btn:active {
    transform: translateY(0);
}

/* Tooltip styling */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    max-width: 250px;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.tooltip.show {
    opacity: 1;
}

/* Responsive design for horizontal working calculation */
@media (max-width: 768px) {
    .working-horizontal-line {
        flex-direction: column;
        gap: 15px;
    }
    
    .working-operator {
        transform: rotate(90deg);
        height: 30px;
        margin: 5px 0;
    }
    
    .working-amount {
        min-width: 200px;
    }
}

@media (max-width: 480px) {
    .container {
        margin: 5px;
        border-radius: 10px;
    }
    
    .section {
        padding: 12px 15px;
    }
    
    .section-header h3 {
        font-size: 1em;
    }
    
    .balance-amount {
        font-size: 1.5em;
    }
    
    .formula {
        font-size: 1em;
        flex-direction: column;
        gap: 5px;
    }
    
    .formula-part, .formula-result {
        min-width: 120px;
    }
    
    .working-value {
        font-size: 1.1em;
    }
    
    .working-operator {
        font-size: 1.5em;
    }
}

/* Animation for value changes */
.value-change {
    animation: highlight 0.6s ease-in-out;
}

@keyframes highlight {
    0% { background-color: #fff3cd; }
    50% { background-color: #ffeaa7; }
    100% { background-color: transparent; }
}