* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #3b82f6;
    --success: #16a34a;
    --warning: #ea580c;
    --danger: #dc2626;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-accent: #eff6ff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 0.5rem;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    min-height: 100vh;
    padding: 1.5rem 1rem;
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

.header {
    text-align: center;
    margin-bottom: 2rem;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.header p {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.main-grid {
    display: grid;
    grid-template-columns: 380px 1fr 340px;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 1200px) {
    .main-grid {
        grid-template-columns: 1fr 1fr;
    }
    .guide-section {
        grid-column: 1 / -1;
    }
}

@media (max-width: 768px) {
    .main-grid {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--bg-primary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-description {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.card-content {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

input[type="number"],
input[type="text"],
select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9375rem;
    transition: all 0.15s;
    background: var(--bg-primary);
    color: var(--text-primary);
}

input[type="number"]:hover,
input[type="text"]:hover,
select:hover {
    border-color: var(--border-strong);
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-group {
    position: relative;
}

.input-suffix {
    position: absolute;
    right: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.875rem;
    pointer-events: none;
}

.toggle-group {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.25rem;
    background: var(--bg-secondary);
}

.toggle-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    border-radius: calc(var(--radius) - 0.25rem);
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.toggle-btn:hover {
    color: var(--text-primary);
}

.toggle-btn.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.advanced-options {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg-accent);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.advanced-title {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.875rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.advanced-title::after {
    content: '▼';
    font-size: 0.625rem;
    margin-left: auto;
    transition: transform 0.2s;
}

.advanced-title.collapsed::after {
    transform: rotate(-90deg);
}

.advanced-content {
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.advanced-content.collapsed {
    max-height: 0 !important;
}

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

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

.result-item.highlight {
    background: var(--bg-accent);
    padding: 0.875rem 1rem;
    margin: 0 -1rem;
    border-radius: var(--radius);
}

.result-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.result-label.primary {
    color: var(--text-primary);
    font-weight: 600;
}

.result-value {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9375rem;
    text-align: right;
    font-family: 'Courier New', monospace;
}

.result-value.primary {
    color: var(--primary);
    font-size: 1.125rem;
}

.result-value.danger {
    color: var(--danger);
}

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

.result-highlight {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.result-highlight .label {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-bottom: 0.5rem;
}

.result-highlight .value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    line-height: 1;
}

.result-highlight .subtitle {
    font-size: 0.8125rem;
    opacity: 0.85;
}

.breakdown-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.breakdown-card {
    background: var(--bg-accent);
    border-radius: var(--radius);
    padding: 1rem;
    border: 1px solid var(--border);
}

.breakdown-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    font-weight: 500;
}

.breakdown-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.25rem;
}

.btn {
    flex: 1;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.btn:hover {
    background: var(--bg-secondary);
    border-color: var(--border-strong);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--success);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    transform: translateY(200%);
    transition: transform 0.3s;
    z-index: 1000;
    font-size: 0.875rem;
    font-weight: 500;
}

.toast.show {
    transform: translateY(0);
}

.info-box {
    background: var(--bg-accent);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-top: 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.range-slider {
    margin-top: 0.5rem;
}

.range-slider input[type="range"] {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.range-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: var(--shadow-sm);
}

.range-slider input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: var(--shadow-sm);
}

.range-value {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.375rem;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    margin-top: 0.5rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    background: var(--bg-primary);
}

.radio-label:hover {
    border-color: var(--border-strong);
    background: var(--bg-secondary);
}

.radio-label input[type="radio"] {
    margin: 0;
    cursor: pointer;
}

.radio-label input[type="radio"]:checked + span {
    font-weight: 600;
    color: var(--primary);
}

.radio-label:has(input[type="radio"]:checked) {
    border-color: var(--primary);
    background: var(--bg-accent);
}

.bhxh-input-section {
    transition: opacity 0.2s;
}

.guide-section {
    position: sticky;
    top: 1.5rem;
}

.guide-item {
    margin-bottom: 1rem;
}

.guide-item:last-child {
    margin-bottom: 0;
}

.guide-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
    margin-bottom: 0.375rem;
}

.guide-value {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    line-height: 1.5;
}

.guide-formula {
    background: var(--bg-tertiary);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-family: 'Courier New', monospace;
    font-size: 0.8125rem;
    color: var(--text-primary);
    margin-top: 0.375rem;
    border-left: 2px solid var(--primary);
}

.tax-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
    font-size: 0.8125rem;
}

.tax-table th,
.tax-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.tax-table th {
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.tax-table td {
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 1.5rem;
    }

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

    .result-highlight .value {
        font-size: 1.75rem;
    }

    .action-buttons {
        flex-direction: column;
    }

    .toast {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
    }

    .guide-section {
        position: static;
    }
}

.section-divider {
    height: 1px;
    background: var(--border);
    margin: 1rem 0;
}

.calculation-flow {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    border-left: 3px solid var(--primary);
}

.calculation-step {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.875rem;
}

.calculation-step:not(:last-child) {
    border-bottom: 1px dashed var(--border);
}

.step-label {
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.step-operator {
    color: var(--text-muted);
    font-weight: 600;
}

.step-value {
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
}

.step-result {
    padding-top: 0.75rem;
    margin-top: 0.75rem;
    border-top: 2px solid var(--primary);
    font-size: 0.9375rem;
}

.step-result .step-value {
    color: var(--primary);
    font-size: 1.125rem;
}

.compact-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 640px) {
    .compact-row {
        grid-template-columns: 1fr;
    }
}
