/**
 * Estilos - Calculadora Salario
 * @author Martín Solano
 * @version 2026.1
 */

/* ================================================================
   VARIABLES CSS
   ================================================================ */
:root {
    --bg-primary: #FAFBFC;
    --bg-card: #FFFFFF;
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --accent: #4f46e5;
    --accent-light: #eef2ff;
    --accent-hover: #4338ca;
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --error: #ef4444;
    --error-light: #fef2f2;
    --border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ================================================================
   RESET Y BASE
   ================================================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ================================================================
   LAYOUT PRINCIPAL
   ================================================================ */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 40px 24px 60px;
}

header {
    text-align: center;
    margin-bottom: 24px;
}

.badge {
    display: inline-block;
    background: var(--accent-light);
    color: var(--accent);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.badge-version {
    background: var(--success-light);
    color: var(--success);
    font-size: 11px;
}

.badge-year {
    background: var(--success);
    color: white;
    font-size: 11px;
    padding: 4px 10px;
}

h1 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: 400;
}

/* ================================================================
   SELECTOR DE COMUNIDAD AUTÓNOMA (Nuevo diseño)
   ================================================================ */
.comunidad-section {
    margin-bottom: 24px;
    position: relative;
}

.comunidad-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.comunidad-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.comunidad-button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.comunidad-button:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
}

.comunidad-button.open {
    border-color: var(--accent);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.comunidad-flag {
    font-size: 28px;
    line-height: 1;
}

.comunidad-name {
    flex: 1;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.comunidad-arrow {
    font-size: 12px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.comunidad-button.open .comunidad-arrow {
    transform: rotate(180deg);
}

.comunidad-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 2px solid var(--accent);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    max-height: 350px;
    overflow: hidden;
}

.comunidad-dropdown.open {
    display: block;
}

.comunidad-search-wrapper {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

.comunidad-search {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

.comunidad-search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.comunidad-list {
    max-height: 280px;
    overflow-y: auto;
}

.comunidad-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s ease;
    border-left: 3px solid transparent;
}

.comunidad-item:hover {
    background: var(--accent-light);
}

.comunidad-item.selected {
    background: var(--accent-light);
    border-left-color: var(--accent);
}

.comunidad-item-flag {
    font-size: 22px;
}

.comunidad-item-name {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
}

.comunidad-item-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.comunidad-item-badge.foral {
    background: var(--warning-light);
    color: var(--warning);
}

.comunidad-item-badge.bonificacion {
    background: var(--success-light);
    color: var(--success);
}

.comunidad-info {
    display: none;
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--warning-light);
    border-radius: var(--radius-sm);
    font-size: 13px;
    border-left: 3px solid var(--warning);
}

.foral-badge {
    display: inline-block;
    background: var(--warning);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 11px;
    margin-right: 8px;
}

.foral-note {
    color: var(--text-secondary);
}

.error-msg {
    color: var(--error);
}

/* ================================================================
   TARJETAS
   ================================================================ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 20px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header .section-title {
    margin-bottom: 0;
}

/* ================================================================
   TOGGLE DE MODO (BRUTO/NETO)
   ================================================================ */
.mode-toggle {
    display: flex;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 24px;
}

.mode-btn {
    flex: 1;
    padding: 12px 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: 6px;
    transition: var(--transition);
}

.mode-btn.active {
    background: var(--bg-card);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.mode-btn:hover:not(.active) {
    color: var(--text-primary);
}

/* ================================================================
   INPUT PRINCIPAL
   ================================================================ */
.main-input-wrapper {
    position: relative;
    margin-bottom: 8px;
}

.main-input {
    width: 100%;
    padding: 20px 60px 20px 24px;
    font-size: 32px;
    font-weight: 600;
    font-family: inherit;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    transition: var(--transition);
    text-align: left;
}

.main-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-light);
}

.currency-symbol {
    position: absolute;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 24px;
    font-weight: 500;
    color: var(--text-muted);
}

.input-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* ================================================================
   TOGGLE PERÍODO ANUAL/MENSUAL
   ================================================================ */
.period-toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.period-toggle-row .input-hint {
    margin-bottom: 0;
}

.period-toggle {
    display: flex;
    background: var(--bg-primary);
    border-radius: 6px;
    padding: 2px;
}

.period-btn {
    padding: 6px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: 4px;
    transition: var(--transition);
}

.period-btn.active {
    background: var(--bg-card);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.period-btn:hover:not(.active) {
    color: var(--text-secondary);
}

/* ================================================================
   CONTROLES DE FORMULARIO
   ================================================================ */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-control {
    padding: 12px 16px;
    font-size: 15px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    transition: var(--transition);
    appearance: none;
    -webkit-appearance: none;
}

select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

/* ================================================================
   TARJETA DE RESULTADO
   ================================================================ */
.result-card {
    background: linear-gradient(135deg, var(--success-light) 0%, #d1fae5 100%);
    border: 1px solid #a7f3d0;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.result-label {
    font-size: 14px;
    font-weight: 500;
    color: #047857;
}

.result-period {
    font-size: 12px;
    color: #059669;
    background: rgba(16, 185, 129, 0.15);
    padding: 4px 10px;
    border-radius: 12px;
}

.result-value {
    font-size: 48px;
    font-weight: 700;
    color: #047857;
    letter-spacing: -1px;
    margin-bottom: 4px;
    transition: var(--transition);
}

.result-monthly {
    font-size: 15px;
    color: #059669;
}

/* Avisos informativos en resultado */
.result-notices {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.result-notice {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.5);
}

.result-notice.info {
    color: #0369a1;
    background: rgba(14, 165, 233, 0.1);
}

.result-notice.warning {
    color: #b45309;
    background: rgba(245, 158, 11, 0.15);
}

.result-notice .notice-icon {
    flex-shrink: 0;
}

/* Tooltips */
.tooltip-trigger {
    position: relative;
    cursor: help;
    border-bottom: 1px dotted var(--text-muted);
}

.tooltip-trigger::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 12px;
    background: var(--text-primary);
    color: white;
    font-size: 12px;
    font-weight: 400;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 100;
    max-width: 250px;
    white-space: normal;
    text-align: center;
}

.tooltip-trigger:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ================================================================
   DESGLOSE
   ================================================================ */
.breakdown-list {
    list-style: none;
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    transition: var(--transition);
}

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

.breakdown-item:hover {
    background: var(--bg-primary);
    margin: 0 -16px;
    padding-left: 16px;
    padding-right: 16px;
    border-radius: var(--radius-sm);
}

.breakdown-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--text-secondary);
}

.breakdown-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.breakdown-icon.tax {
    background: #fef2f2;
    color: #dc2626;
}

.breakdown-icon.ss {
    background: #fefce8;
    color: #ca8a04;
}

.breakdown-icon.net {
    background: var(--success-light);
    color: var(--success);
}

.breakdown-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.breakdown-value.negative {
    color: #dc2626;
}

.breakdown-value.positive {
    color: var(--success);
}

.breakdown-percent {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 6px;
}

/* ================================================================
   RESUMEN MENSUAL
   ================================================================ */
.info-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.info-item {
    text-align: center;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

.info-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.info-label {
    font-size: 12px;
    color: var(--text-muted);
}

/* Toggle de pagas */
.pagas-toggle {
    display: flex;
    background: var(--bg-primary);
    border-radius: 6px;
    padding: 2px;
}

.pagas-btn {
    padding: 4px 10px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: 4px;
    transition: var(--transition);
}

.pagas-btn.active {
    background: var(--bg-card);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.pagas-btn:hover:not(.active) {
    color: var(--text-secondary);
}

/* ================================================================
   TABLA IRPF
   ================================================================ */
.details-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out;
}

.details-panel.open {
    max-height: 500px;
    overflow-x: auto;
    overflow-y: visible;
}

.irpf-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.irpf-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
    font-size: 13px;
    min-width: 400px;
}

.irpf-table th,
.irpf-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.irpf-table th {
    background: var(--bg-primary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.irpf-table tr:last-child td {
    border-bottom: none;
}

.irpf-table .highlight {
    background: var(--accent-light);
    font-weight: 500;
}

.toggle-details {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 16px;
    padding: 0;
}

.toggle-details:hover {
    text-decoration: underline;
}

/* ================================================================
   MODO DE CÁLCULO
   ================================================================ */
.calculation-mode-section {
    margin-top: 20px;
    padding: 16px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    border: 1px solid #dee2e6;
}

.mode-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.mode-label {
    font-size: 14px;
    font-weight: 600;
    color: #495057;
}

.mode-info-icon {
    font-size: 16px;
    cursor: help;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.mode-info-icon:hover {
    opacity: 1;
}

.calculation-mode-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.calc-mode-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.2s;
}

.calc-mode-btn .mode-icon {
    font-size: 18px;
}

.calc-mode-btn:hover {
    border-color: #4f46e5;
    background: #f8f9ff;
}

.calc-mode-btn.active {
    background: #4f46e5;
    border-color: #4f46e5;
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.mode-description {
    font-size: 12px;
    line-height: 1.5;
    color: #6c757d;
    margin: 0;
    padding: 8px 12px;
    background: white;
    border-radius: 6px;
    border-left: 3px solid #4f46e5;
}

.mode-description strong {
    color: #495057;
}

/* ================================================================
   OPCIONES AVANZADAS (Colapsable)
   ================================================================ */
.advanced-section {
    margin-top: 24px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.advanced-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 10px 14px;
    margin: 0 -4px;
    border-radius: 8px;
    list-style: none;
    user-select: none;
    transition: all 0.2s;
    background: transparent;
}

.advanced-toggle::-webkit-details-marker {
    display: none;
}

.advanced-toggle:hover {
    color: var(--text-primary);
    background: rgba(79, 70, 229, 0.05);
}

details[open] .advanced-toggle {
    color: var(--accent);
    margin-bottom: 8px;
}

.advanced-icon {
    font-size: 14px;
    opacity: 0.8;
}

.advanced-arrow {
    margin-left: auto;
    font-size: 12px;
    font-weight: bold;
    transition: transform 0.2s;
    opacity: 0.5;
}

details[open] .advanced-arrow {
    transform: rotate(90deg);
}

.advanced-content {
    padding: 8px 0 0 0;
    animation: fadeIn 0.2s ease;
}

.advanced-content .form-grid {
    gap: 16px;
}

.advanced-content .form-group {
    margin-bottom: 0;
}

.advanced-content .form-control {
    padding: 14px 16px;
    font-size: 15px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.advanced-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 20px;
    padding: 12px 14px;
    background: rgba(79, 70, 229, 0.05);
    border-radius: 8px;
    border-left: 3px solid var(--accent);
    line-height: 1.5;
}

/* ================================================================
   FOOTER
   ================================================================ */
footer {
    text-align: center;
    padding-top: 32px;
    border-top: 1px solid var(--border);
    margin-top: 16px;
}

.footer-text {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.8;
}

.footer-version {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 12px;
    opacity: 0.7;
}

.footer-legal {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    line-height: 1.6;
}

.footer-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-link:hover {
    color: white;
    text-decoration: underline;
}

.footer-link:hover {
    text-decoration: underline;
}

/* ================================================================
   ANIMACIONES
   ================================================================ */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.calculating {
    animation: pulse 1s ease-in-out infinite;
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 640px) {
    .container {
        padding: 24px 16px 40px;
    }

    h1 {
        font-size: 26px;
    }

    .card {
        padding: 24px;
    }

    .main-input {
        font-size: 26px;
        padding: 16px 50px 16px 20px;
    }

    .currency-symbol {
        font-size: 20px;
        right: 20px;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .result-value {
        font-size: 36px;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }

    .section-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    /* Tabla IRPF responsive */
    .irpf-table {
        font-size: 12px;
        min-width: 350px;
    }

    .irpf-table th,
    .irpf-table td {
        padding: 8px 6px;
    }

    .irpf-table th {
        font-size: 10px;
    }

    /* Prevenir zoom automático en iOS */
    .comunidad-selector-btn,
    .comunidad-search {
        font-size: 16px !important;
    }
}
