* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252542;
    --accent-primary: #00d4ff;
    --accent-secondary: #7b2cbf;
    --accent-success: #06ffa5;
    --accent-warning: #ffbe0b;
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --border-color: #52525b;  /* Updated for WCAG contrast 3.5:1 (was #3f3f46 at 2.8:1) */
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== ACCESSIBILITY FEATURES ===== */

/* Skip Navigation Link - WCAG 2.4.1 */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--accent-primary);
    color: var(--bg-primary);
    padding: 8px 16px;
    text-decoration: none;
    z-index: 1000;
    border-radius: 0 0 4px 0;
    font-weight: 600;
}

.skip-link:focus {
    top: 0;
    outline: 2px solid white;
    outline-offset: 2px;
}

/* Screen Reader Only - for hidden but accessible content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Enhanced Focus Indicators - WCAG 2.4.7 */
*:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(0, 212, 255, 0.2);
}

button:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 4px;
    box-shadow: 0 0 0 4px rgba(0, 212, 255, 0.3);
}

a:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    text-decoration: underline;
    text-decoration-thickness: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    *:focus {
        outline-width: 3px;
    }
}

/* ===== END ACCESSIBILITY FEATURES ===== */

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

header h1 {
    font-size: 1.8rem;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 5px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    background: var(--bg-secondary);
    padding: 10px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.tab-btn {
    padding: 12px 24px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.tab-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    color: white;
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Calculator Grid */
.calculator-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

/* Input Section */
.input-section, .results-section {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.input-section h2, .results-section h2 {
    color: var(--accent-primary);
    margin-bottom: 16px;
    font-size: 1.3rem;
}

.input-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 16px;
}

@media (max-width: 768px) {
    .input-columns {
        grid-template-columns: 1fr;
    }
}

.input-column h3 {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 12px;
    font-weight: 600;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.currency {
    position: absolute;
    left: 16px;
    color: var(--text-secondary);
    font-weight: 600;
    pointer-events: none;
    z-index: 1;
}

.input-wrapper input {
    padding-left: 45px !important;
}

input[type="number"], input[type="text"], select {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

input[type="number"]:focus, input[type="text"]:focus, select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

input[type="range"] {
    width: 100%;
    height: 5px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
    margin-top: 6px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-primary);
    cursor: pointer;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 212, 255, 0.4);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent-primary);
    cursor: pointer;
    border-radius: 50%;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 212, 255, 0.4);
}

select {
    cursor: pointer;
}

/* ===== INPUT VALIDATION & ERROR STATES ===== */
/* WCAG 3.3.1 Error Identification, 3.3.3 Error Suggestion */

.input-error {
    border-color: #ff6b6b !important;
    background: rgba(255, 107, 107, 0.05) !important;
    animation: shake 0.3s ease-in-out;
}

.input-error:focus {
    border-color: #ff6b6b !important;
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.2) !important;
}

.error-message {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 8px 12px;
    background: rgba(255, 107, 107, 0.1);
    border-left: 3px solid #ff6b6b;
    border-radius: 4px;
    color: #ff6b6b;
    font-size: 0.85rem;
    font-weight: 500;
}

.error-message::before {
    content: '⚠️';
    font-size: 1rem;
}

/* Shake animation for error state */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* High contrast mode support for errors */
@media (prefers-contrast: high) {
    .input-error {
        border-width: 3px !important;
    }

    .error-message {
        border-left-width: 4px;
        font-weight: 600;
    }
}

/* ===== END INPUT VALIDATION & ERROR STATES ===== */

/* Calculate Button */
.calculate-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 16px rgba(0, 212, 255, 0.3);
}

.calculate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(0, 212, 255, 0.4);
}

.calculate-btn:active {
    transform: translateY(0);
}

/* Button Group for Calculate and Print */
.button-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.button-group .calculate-btn {
    flex: 1;
}

.print-btn {
    padding: 16px 24px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.print-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 212, 255, 0.2);
}

.print-btn:active {
    transform: translateY(0);
}

/* Hide print button when printing */
@media print {
    .print-btn {
        display: none !important;
    }
}

/* Results Section */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

.result-card {
    background: var(--bg-tertiary);
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    transition: all 0.3s ease;
}

.result-card:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.result-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.result-value {
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 700;
}

.result-value.highlight {
    background: linear-gradient(135deg, var(--accent-success) 0%, var(--accent-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Charts */
.chart-container {
    background: var(--bg-tertiary);
    padding: 24px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 2px solid var(--border-color);
}

.chart-container canvas {
    max-height: 400px;
}

/* Breakdown Section */
.breakdown-section {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}

.breakdown-section h2 {
    color: var(--accent-primary);
    margin-bottom: 20px;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--bg-tertiary);
}

th {
    padding: 16px;
    text-align: left;
    color: var(--accent-primary);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

tbody tr {
    transition: background 0.2s ease;
}

tbody tr:hover {
    background: var(--bg-tertiary);
}

/* Footer */
footer {
    text-align: center;
    padding: 30px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 12px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.85rem;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    .tabs {
        flex-wrap: nowrap;
        padding: 8px;
    }

    .tab-btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .result-value {
        font-size: 1.3rem;
    }

    .button-group {
        flex-direction: column;
    }

    .button-group .calculate-btn,
    .print-btn {
        width: 100%;
    }

    /* Larger touch targets for mobile - WCAG 2.5.5 */
    button, .calculate-btn, .print-btn {
        min-height: 44px;
        min-width: 44px;
    }

    input[type="number"], 
    input[type="text"], 
    select {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .chart-container {
        padding: 16px;
    }

    .chart-container canvas {
        max-height: 300px;
    }

    table {
        font-size: 0.85rem;
    }

    th, td {
        padding: 10px 8px;
    }

    .input-section, .results-section {
        padding: 16px;
    }

    .breakdown-section {
        padding: 20px;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    header h1 {
        font-size: 1.3rem;
    }

    .calculate-btn {
        font-size: 1rem;
        padding: 14px;
    }

    .result-card {
        padding: 16px;
    }

    .result-value {
        font-size: 1.2rem;
    }

    .chart-container canvas {
        max-height: 250px;
    }
}

/* Landscape orientation optimization */
@media (max-width: 768px) and (orientation: landscape) {
    .chart-container canvas {
        max-height: 200px;
    }

    .input-columns {
        grid-template-columns: 1fr 1fr;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Increase spacing for touch */
    .form-group {
        margin-bottom: 20px;
    }

    .results-grid {
        gap: 20px;
    }

    /* Remove hover effects on touch devices */
    .result-card:hover {
        transform: none;
    }

    .calculate-btn:hover {
        transform: none;
    }

    .print-btn:hover {
        transform: none;
    }
}
