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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    font-size: 14px;
    line-height: 1.4;
    /* Improve accessibility */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Focus styles for better accessibility */
*:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #667eea;
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 1000;
}

.skip-link:focus {
    top: 6px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    min-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
}

/* Header styles */
.header {
    text-align: center;
    margin-bottom: 20px;
    color: white;
}

.header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.header p {
    font-size: 16px;
    opacity: 0.9;
    font-weight: 300;
}

/* Main content */
.main-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.calculator-card {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    width: 100%;
    max-width: 1000px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    min-height: 600px;
}

/* Input section */
.input-section {
    padding: 30px;
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
}

.input-section h2 {
    font-size: 20px;
    font-weight: 600;
    color: #1a202c;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-group {
    margin-bottom: 18px;
    position: relative;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #4a5568;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    /* Improve accessibility */
    cursor: pointer;
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.3s ease;
    background: white;
    /* Improve accessibility */
    min-height: 44px;
    /* Better touch target */
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.input-group input::placeholder {
    color: #a0aec0;
    font-size: 13px;
}

.input-hint {
    display: block;
    font-size: 11px;
    color: #718096;
    margin-top: 4px;
    line-height: 1.3;
}

/* Period and rate input groups */
.period-input-group,
.rate-input-group {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.period-input-group input,
.rate-input-group input {
    flex: 2;
    min-width: 0;
}

.period-select,
.rate-select,
.calculation-select {
    flex: 1;
    min-width: 100px;
    max-width: 140px;
    font-size: 13px;
    /* Improve accessibility */
    min-height: 44px;
}

/* Make calculation type select stretch to full width */
.calculation-select {
    flex: none;
    min-width: auto;
    max-width: none;
    width: 100%;
}

/* Calculate button */
.calculate-btn {
    width: 100%;
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
    /* Improve accessibility and touch targets */
    min-height: 48px;
    position: relative;
}

.calculate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}

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

.calculate-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

.calculate-btn.loading {
    opacity: 0.8;
    cursor: not-allowed;
}

/* Share button */
.share-btn {
    width: 100%;
    padding: 12px 24px;
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 15px;
    /* Improve accessibility and touch targets */
    min-height: 48px;
}

.share-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(37, 211, 102, 0.3);
}

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

.share-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.3);
}

/* Toast notification styles */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    cursor: pointer;
    user-select: none;
}

/* Results section */
.results-section {
    padding: 30px;
    background: white;
    display: none;
}

.results-section h2 {
    font-size: 20px;
    font-weight: 600;
    color: #1a202c;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.result-card {
    background: #f8fafc;
    border-radius: 12px;
    padding: 20px;
    border: 1px solid #e2e8f0;
    transition: all 0.3s ease;
}

.result-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

.result-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    margin-bottom: 12px;
}

.result-content h3 {
    font-size: 12px;
    font-weight: 600;
    color: #4a5568;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.result-content p {
    font-size: 20px;
    font-weight: 700;
    color: #1a202c;
    margin: 0;
}

/* Loan summary */
.loan-summary {
    background: #f8fafc;
    border-radius: 12px;
    padding: 20px;
    border: 1px solid #e2e8f0;
    margin-bottom: 20px;
}

.loan-summary h3 {
    font-size: 16px;
    font-weight: 600;
    color: #1a202c;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
    font-size: 14px;
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-item.total {
    font-weight: 600;
    font-size: 16px;
    color: #1a202c;
    border-top: 2px solid #667eea;
    padding-top: 12px;
    margin-top: 8px;
}

.summary-item span:first-child {
    color: #4a5568;
}

.summary-item span:last-child {
    font-weight: 500;
    color: #1a202c;
}

/* Footer */
.footer {
    text-align: center;
    margin-top: 20px;
    color: white;
    opacity: 0.8;
    font-size: 12px;
}

/* Error states */
.input-group.error input,
.input-group.error select {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.error-message {
    color: #ef4444;
    font-size: 12px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.input-group.error .error-message {
    display: block;
}

/* Loading animation */
.calculate-btn.loading i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Results animation */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.results-section {
    animation: fadeInUp 0.5s ease-out;
}

/* Responsive design */
@media (max-width: 768px) {
    body {
        padding: 15px;
        font-size: 13px;
    }

    .header h1 {
        font-size: 24px;
    }

    .header p {
        font-size: 14px;
    }

    .calculator-card {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .input-section {
        padding: 25px 20px;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }

    .results-section {
        padding: 25px 20px;
    }

    .result-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .input-section h2,
    .results-section h2 {
        font-size: 18px;
        margin-bottom: 15px;
    }

    .input-group {
        margin-bottom: 15px;
    }

    .input-group label {
        font-size: 12px;
    }

    .input-group input,
    .input-group select {
        padding: 8px 10px;
        font-size: 13px;
        /* Ensure minimum touch target size */
        min-height: 44px;
    }

    .period-input-group,
    .rate-input-group {
        flex-direction: column;
        gap: 8px;
    }

    .period-input-group input,
    .rate-input-group input {
        flex: none;
    }

    .period-select,
    .rate-select {
        flex: none;
        min-width: auto;
        max-width: none;
        width: 100%;
    }

    .calculate-btn {
        padding: 10px 20px;
        font-size: 14px;
        /* Ensure minimum touch target size */
        min-height: 48px;
    }

    .calculation-select {
        font-size: 11px;
    }

    .result-card {
        padding: 15px;
    }

    .result-content h3 {
        font-size: 11px;
    }

    .result-content p {
        font-size: 18px;
    }

    .loan-summary {
        padding: 15px;
    }

    .loan-summary h3 {
        font-size: 15px;
    }

    .summary-item {
        font-size: 13px;
    }

    .summary-item.total {
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }

    .header h1 {
        font-size: 20px;
    }

    .header p {
        font-size: 13px;
    }

    .input-section,
    .results-section {
        padding: 20px 15px;
    }

    .input-section h2,
    .results-section h2 {
        font-size: 16px;
    }

    .period-input-group,
    .rate-input-group {
        flex-direction: column;
        gap: 6px;
    }

    .period-input-group input,
    .rate-input-group input {
        font-size: 12px;
    }

    .period-select,
    .rate-select {
        font-size: 12px;
    }

    .result-grid {
        gap: 10px;
    }

    .result-card {
        padding: 12px;
    }

    .result-content p {
        font-size: 16px;
    }

    .calculation-select {
        font-size: 11px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {

    .input-group input,
    .input-group select {
        border-width: 3px;
    }

    .calculate-btn,
    .share-btn {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .calculate-btn:hover,
    .share-btn:hover,
    .result-card:hover {
        transform: none;
    }
}

/* Calculation description section */
.calculation-description {
    background: #f8fafc;
    border-radius: 12px;
    padding: 20px;
    border: 1px solid #e2e8f0;
    margin-top: 20px;
}

.calculation-description h3 {
    font-size: 16px;
    font-weight: 600;
    color: #1a202c;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.calculation-description h3::before {
    content: '\f05a';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    color: #667eea;
}

.calculation-description p {
    font-size: 14px;
    line-height: 1.6;
    color: #4a5568;
    margin-bottom: 12px;
}

.calculation-description ul {
    margin: 12px 0;
    padding-left: 20px;
}

.calculation-description li {
    font-size: 14px;
    line-height: 1.6;
    color: #4a5568;
    margin-bottom: 6px;
}

.calculation-description .formula {
    background: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #2d3748;
    margin: 12px 0;
    border-left: 4px solid #667eea;
}

.calculation-description .note {
    background: #fef5e7;
    border: 1px solid #f6ad55;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    color: #744210;
    margin-top: 12px;
}

.calculation-select {
    font-size: 11px;
}

.calculation-description {
    padding: 15px;
    margin-top: 15px;
}

.calculation-description h3 {
    font-size: 15px;
}

.calculation-description p,
.calculation-description li {
    font-size: 13px;
}

.calculation-description .formula {
    font-size: 12px;
    padding: 10px;
}

.calculation-description .note {
    font-size: 12px;
    padding: 10px;
}

/* Responsive styles for calculation description */
@media (max-width: 768px) {
    .calculation-description {
        padding: 15px;
        margin-top: 15px;
    }

    .calculation-description h3 {
        font-size: 15px;
    }

    .calculation-description p,
    .calculation-description li {
        font-size: 13px;
    }

    .calculation-description .formula {
        font-size: 12px;
        padding: 10px;
    }

    .calculation-description .note {
        font-size: 12px;
        padding: 10px;
    }
}

@media (max-width: 480px) {
    .calculation-description {
        padding: 12px;
        margin-top: 12px;
    }

    .calculation-description h3 {
        font-size: 14px;
    }

    .calculation-description p,
    .calculation-description li {
        font-size: 12px;
    }

    .calculation-description .formula {
        font-size: 11px;
        padding: 8px;
    }

    .calculation-description .note {
        font-size: 11px;
        padding: 8px;
    }
}