/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans TC', 'Noto Sans JP', sans-serif;
    --border-radius: 8px;
    --transition: all 0.3s ease;
}

/* Theme: Light */
.theme-light {
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a6a;
    --text-muted: #8888a0;
    --border-color: #e0e4e8;
    --accent-color: #4361ee;
    --accent-hover: #3651de;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
    --input-bg: #ffffff;
    --chart-grid: rgba(0, 0, 0, 0.1);
    --theme-btn-bg: #f0f2f5;
    --theme-btn-active: #4361ee;
}

/* Theme: Dark */
.theme-dark {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1f2a48;
    --text-primary: #e8e8f0;
    --text-secondary: #b8b8d0;
    --text-muted: #6868a0;
    --border-color: #2a2a4e;
    --accent-color: #4cc9f0;
    --accent-hover: #3db9e0;
    --success-color: #34d399;
    --warning-color: #fbbf24;
    --error-color: #f87171;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
    --input-bg: #2a2a4e;
    --chart-grid: rgba(255, 255, 255, 0.1);
    --theme-btn-bg: #2a2a4e;
    --theme-btn-active: #4cc9f0;
}

/* Theme: Night */
.theme-night {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: #21262d;
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --text-muted: #484f58;
    --border-color: #30363d;
    --accent-color: #58a6ff;
    --accent-hover: #79b8ff;
    --success-color: #3fb950;
    --warning-color: #d29922;
    --error-color: #f85149;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.6);
    --input-bg: #0d1117;
    --chart-grid: rgba(255, 255, 255, 0.08);
    --theme-btn-bg: #21262d;
    --theme-btn-active: #58a6ff;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: var(--transition);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
    min-height: 100vh;
}

/* Ensure padding on all sides */
body {
    padding: 0;
    margin: 0;
}

html {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Header */
.header {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 20px 30px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.header h1 {
    font-size: 1.8rem;
    color: var(--accent-color);
    font-weight: 700;
}

.header-controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.control-group label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.control-group select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    min-width: 120px;
}

.control-group select:hover {
    border-color: var(--accent-color);
}

.control-group select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
}

/* Theme Toggle Button - 單一切換按鈕 */
.theme-toggle {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--theme-btn-bg);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: var(--shadow);
}

.theme-toggle:hover {
    transform: scale(1.1) rotate(15deg);
    box-shadow: var(--shadow-lg);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-toggle .theme-icon {
    font-size: 1.5rem;
    transition: all 0.3s ease;
    line-height: 1;
}

.theme-toggle:hover .theme-icon {
    transform: scale(1.1);
}

/* Theme icon animation */
@keyframes themeSwitch {
    0% {
        transform: scale(1) rotate(0deg);
    }

    50% {
        transform: scale(0.8) rotate(180deg);
    }

    100% {
        transform: scale(1) rotate(360deg);
    }
}

.theme-toggle.switching .theme-icon {
    animation: themeSwitch 0.4s ease;
}

/* Settings Dropdown */
.settings-dropdown {
    position: relative;
}

.settings-toggle {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--theme-btn-bg);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    font-size: 1.5rem;
}

.settings-toggle:hover {
    transform: scale(1.1) rotate(45deg);
    box-shadow: var(--shadow-lg);
}

.settings-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 100;
}

.settings-dropdown.active .settings-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.settings-group {
    margin-bottom: 12px;
}

.settings-group:last-child {
    margin-bottom: 0;
}

.settings-group label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.settings-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

.settings-group select:hover {
    border-color: var(--accent-color);
}

.settings-group select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 420px 1fr;
    gap: 24px;
}

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

    /* Disable sticky input when stacked to prevent overlap */
    .input-section {
        position: relative;
        top: 0;
        max-height: none;
    }
}

/* Input Section */
.input-section {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow);
    max-height: calc(100vh - 150px);
    overflow-y: auto;
    /* Default relative for mobile/tablet to prevent overlap */
    position: relative;
    top: 0;
}

/* Enable sticky only on large screens */
@media (min-width: 1025px) {
    .input-section {
        position: sticky;
        top: 20px;
    }
}

/* Custom Scrollbar for Input Section */
.input-section::-webkit-scrollbar {
    width: 8px;
}

.input-section::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

.input-section::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.4);
    border-radius: 4px;
}

.input-section::-webkit-scrollbar-thumb:hover {
    background: rgba(128, 128, 128, 0.6);
}

/* Firefox scrollbar */
.input-section {
    scrollbar-width: thin;
    scrollbar-color: rgba(128, 128, 128, 0.4) transparent;
}


.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 10px;
}

.section-header h2 {
    font-size: 1.3rem;
    margin: 0;
    color: var(--text-primary);
}

.btn-reset {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.btn-reset:hover {
    transform: rotate(180deg) scale(1.1);
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    box-shadow: var(--shadow);
}

.btn-reset:active {
    transform: rotate(180deg) scale(0.95);
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
}

.input-with-unit {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-with-unit input {
    flex: 1;
}

.input-with-unit .unit {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: var(--border-radius);
    color: var(--text-muted);
    font-size: 0.9rem;
    min-width: 60px;
    text-align: center;
}

/* Compact Row - 水平並列 */
.form-row {
    display: flex;
    gap: 10px;
}

.compact-row {
    margin-bottom: 18px;
}

.form-group.compact {
    flex: 1;
    margin-bottom: 0;
}

.form-group.compact label {
    font-size: 0.7rem;
    text-align: center;
    margin-bottom: 4px;
    white-space: nowrap;
}

/* Inline input with unit - 數字和單位同一列 */
.input-inline {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: var(--transition);
}

.input-inline:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
}

.input-inline input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    text-align: center;
    padding: 10px 4px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.input-inline input:focus {
    outline: none;
    box-shadow: none;
}

.unit-inline {
    padding: 10px 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    white-space: nowrap;
}



/* Grace Period Section */
.grace-period-group {
    background: var(--bg-card);
    padding: 16px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.grace-period-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
}

.grace-period-header label {
    margin-bottom: 0;
    font-weight: 600;
}

.grace-period-inputs {
    margin-top: 12px;
    display: none;
}

.grace-period-inputs.active {
    display: block;
}

.input-with-select {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 200px;
}

.input-with-select input {
    flex: 1;
    min-width: 60px;
}

.input-with-select select {
    min-width: 80px;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
    margin-bottom: 0 !important;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: 0.3s;
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.toggle-slider {
    background-color: var(--accent-color);
}

.toggle-switch input:checked+.toggle-slider:before {
    transform: translateX(24px);
}

.hint {
    display: block;
    margin-top: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
}

.loan-type-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.hidden {
    display: none !important;
}

/* Additional Costs */
.costs-section {
    background: var(--bg-card);
    padding: 16px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

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

.costs-header label {
    margin-bottom: 0;
    font-weight: 600;
}

.btn-add {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--accent-color);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.btn-add:hover {
    background: var(--accent-hover);
    transform: scale(1.1);
}

#costsContainer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 12px;
}

/* Custom Scrollbar for Costs */
#costsContainer::-webkit-scrollbar {
    width: 8px;
}

#costsContainer::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

#costsContainer::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

#costsContainer::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.cost-item {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

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

.cost-item input {
    flex: 1;
    padding: 8px 10px;
    font-size: 0.85rem;
}

.cost-item .cost-name {
    flex: 1.5;
}

.cost-item .cost-amount {
    flex: 1;
}

.btn-remove {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: var(--error-color);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.btn-remove:hover {
    opacity: 0.8;
    transform: scale(1.1);
}

.total-costs {
    display: flex;
    justify-content: space-between;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 0.8rem;
    /* Reduced by 20% from default */
    color: var(--text-primary);
}

/* Cost item info - name and badge stacked vertically */
.cost-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cost-info .cost-name {
    font-weight: 500;
    color: var(--text-primary);
}

.cost-info .payment-mode-badge {
    align-self: flex-start;
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 14px 24px;
    border: none;
    border-radius: var(--border-radius);
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 10px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

/* Results Section */
.results-section {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow);
    display: none;
    /* 初始隱藏，計算後才顯示 */
    min-width: 0;
    /* 防止 Grid Item 被內部寬內容撐開 (如 Table/Chart) */
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 10px;
}

.results-header h2 {
    font-size: 1.3rem;
    color: var(--text-primary);
    margin: 0;
}

/* Share Dropdown */
.share-dropdown {
    position: relative;
}

.btn-share-main {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
}

.btn-share-main:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.share-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    min-width: 140px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 100;
}

.share-dropdown.active .share-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s ease;
    text-align: left;
}

.dropdown-item:hover {
    background: var(--bg-primary);
}

.dropdown-item:first-child {
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.dropdown-item:last-child {
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

.dropdown-divider {
    margin: 4px 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

.results-section h3 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

/* Summary Cards - 2x2 Grid */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

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

.card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 20px;
    text-align: center;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.card h3 {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card .value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent-color);
}

/* APR Card - 特殊樣式 */
.card-apr {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
    border: none;
}

.card-apr h3 {
    color: rgba(255, 255, 255, 0.85);
}

.card-apr .value {
    color: white;
    font-size: 1.6rem;
}

/* Monthly Payment Card - 寬限期切換 */
.card-monthly-payment {
    min-height: 120px;
}

.monthly-payment-display {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.grace-toggle-container {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    width: 100%;
}

.grace-payment-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
}

.toggle-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.toggle-label:first-child {
    text-align: right;
}

.toggle-label:last-child {
    text-align: left;
}

/* Mini Toggle Switch */
.mini-toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    margin: 0 !important;
}

.mini-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.mini-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--warning-color);
    transition: 0.3s;
    border-radius: 20px;
}

.mini-toggle-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.mini-toggle input:checked+.mini-toggle-slider {
    background-color: var(--accent-color);
}

.mini-toggle input:checked+.mini-toggle-slider:before {
    transform: translateX(16px);
}

.grace-value {
    font-size: 1.2rem !important;
    color: var(--accent-color);
}

/* Charts */
.charts-container {
    display: grid;
    /* Force 1 column to separate charts into two distinct full-width blocks */
    grid-template-columns: 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

@media (max-width: 900px) {
    .charts-container {
        grid-template-columns: 1fr;
    }
}

.chart-wrapper {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 20px;
    border: 1px solid var(--border-color);
    /* Essential: min-width 0 allows grid item to shrink narrower than content */
    min-width: 0;
}

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

.chart-header h3 {
    margin: 0;
}

.btn-magnify {
    width: 36px;
    height: 36px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-magnify:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: scale(1.1);
}

.chart-actions {
    display: flex;
    gap: 8px;
}

.btn-expand {
    width: 36px;
    height: 36px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-expand:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: scale(1.1);
}

.chart-scroll-container {
    overflow: auto;
    max-height: 320px;
    -webkit-overflow-scrolling: touch;
}

.chart-scroll-container canvas {
    min-width: 100%;
    max-height: 300px;
}

/* Table Header */
.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.table-header h3 {
    margin: 0;
}

/* Fullscreen Modal */
.fullscreen-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 2000;
    display: none;
    flex-direction: column;
    padding: 20px;
}

.fullscreen-modal.active {
    display: flex;
}

.fullscreen-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 16px;
}

.fullscreen-header h3 {
    margin: 0;
    font-size: 1.3rem;
    color: var(--text-primary);
}

.fullscreen-close {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1.6rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.fullscreen-close:hover {
    background: var(--error-color);
    color: white;
}

.fullscreen-body {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.fullscreen-body canvas {
    width: 100% !important;
    height: auto !important;
    max-height: calc(100vh - 120px);
}

.fullscreen-body .table-scroll {
    max-height: calc(100vh - 120px);
    overflow: auto;
}

.fullscreen-body table {
    table-layout: auto;
}

.fullscreen-body th,
.fullscreen-body td {
    padding: 16px;
    white-space: nowrap;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 24px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--error-color);
    color: white;
}

.period-selector {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--border-radius);
}

.period-selector label {
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.period-selector input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    cursor: pointer;
}

.period-selector input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
}

#periodDisplay {
    min-width: 40px;
    text-align: center;
    font-weight: 600;
    color: var(--accent-color);
    font-size: 1.1rem;
}

.period-details {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.detail-item {
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.detail-item .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.detail-item .value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.detail-item.highlight {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
    border: none;
}

.detail-item.highlight .label,
.detail-item.highlight .value {
    color: white;
}

/* Table */
.table-container {
    margin-bottom: 30px;
}

.table-scroll {
    overflow-x: auto;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    max-height: 400px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* iOS 平滑滾動 */
}

/* 美化滾動條（Webkit 瀏覽器）*/
.table-scroll::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.table-scroll::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 4px;
}

.table-scroll::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.table-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    table-layout: fixed;
    min-width: 800px;
    /* 確保表格不會被壓縮，可以水平滾動 */
}

th,
td {
    padding: 14px 12px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Column widths */
th:nth-child(1),
td:nth-child(1) {
    width: 8%;
    text-align: center;
}

th:nth-child(2),
td:nth-child(2) {
    width: 14%;
}

th:nth-child(3),
td:nth-child(3) {
    width: 14%;
}

th:nth-child(4),
td:nth-child(4) {
    width: 14%;
}

th:nth-child(5),
td:nth-child(5) {
    width: 16%;
}

th:nth-child(6),
td:nth-child(6) {
    width: 16%;
}

th:nth-child(7),
td:nth-child(7) {
    width: 18%;
}

th {
    background: var(--bg-card);
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.3px;
    position: sticky;
    top: 0;
    z-index: 10;
}

td {
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    letter-spacing: -0.02em;
}

tbody tr {
    transition: var(--transition);
}

tbody tr:hover {
    background: var(--bg-card);
}

tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}

.theme-dark tbody tr:nth-child(even),
.theme-night tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

/* Grace period rows */
tbody tr.grace-period {
    background: rgba(245, 158, 11, 0.1);
}

tbody tr.grace-period td {
    color: var(--warning-color);
}

/* Export Section */
.export-section {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 20px;
    border: 1px solid var(--border-color);
}

.export-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn-export {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-export:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

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

.btn-share:hover {
    background: var(--accent-hover);
}

/* Footer */
.footer {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 24px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    .header {
        flex-direction: row;
        /* 改為橫向排列 */
        justify-content: space-between;
        /* 左右分散對齊 */
        align-items: center;
        text-align: left;
        /* 標題靠左 */
        padding: 20px;
        /* 與 input-section 一致 */
        flex-wrap: nowrap;
        /* 不換行 */
    }

    .header h1 {
        font-size: 1.3rem;
        /* 縮小字體以適應並排 */
        margin: 0;
    }

    .header-controls {
        justify-content: flex-end;
        /* 按鈕靠右 */
        flex-wrap: nowrap;
        /* 按鈕不換行 */
        gap: 8px;
        /* 縮小按鈕間距 */
    }

    .input-section {
        position: static;
        padding: 20px;
    }

    /* 確保區塊標題不超出邊界 */
    .section-header {
        margin-left: 0;
        margin-right: 0;
    }

    /* 確保所有表單組寬度一致，並移除額外的 padding */
    .form-group {
        width: 100%;
        padding-left: 0;
        padding-right: 0;
        margin-left: 0;
        margin-right: 0;
    }

    .form-group input,
    .form-group select {
        width: 100%;
    }

    /* 確保貸款金額欄位與其他欄位寬度一致 */
    .input-with-unit {
        width: 100%;
    }

    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-container {
        grid-template-columns: 1fr;
    }

    .chart-wrapper canvas {
        max-height: 250px;
    }

    .form-row {
        flex-direction: row;
        gap: 8px;
    }

    .form-group.compact label {
        font-size: 0.65rem;
    }

    .input-inline input {
        font-size: 1rem;
        padding: 8px 2px;
    }

    .unit-inline {
        padding: 8px 6px;
        font-size: 0.7rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 16px;
    }

    .header {
        padding: 18px;
        /* 與 input-section 一致 */
        gap: 8px;
        /* 縮小間距 */
    }

    .header h1 {
        font-size: 1.1rem;
        /* 進一步縮小以適應小螢幕 */
        line-height: 1.2;
    }

    .input-section {
        padding: 18px;
    }

    /* 確保區塊標題在小螢幕上不超出邊界 */
    .section-header {
        margin-left: 0;
        margin-right: 0;
        padding-left: 0;
        padding-right: 0;
    }

    /* 確保所有表單組在小螢幕上寬度一致 */
    .form-group {
        width: 100%;
        margin-bottom: 16px;
        padding-left: 0;
        padding-right: 0;
        margin-left: 0;
        margin-right: 0;
    }

    .form-group input,
    .form-group select {
        width: 100%;
        padding: 10px 12px;
    }

    /* 確保貸款金額欄位在小螢幕上寬度一致 */
    .input-with-unit {
        width: 100%;
        display: flex;
    }

    .input-with-unit input {
        flex: 1;
    }

    .input-with-unit .unit {
        min-width: 60px;
        padding: 10px 12px;
    }

    /* 確保成本區塊也一致 */
    .costs-section {
        padding: 14px;
    }

    /* 確保寬限期區塊也一致 */
    .grace-period-group {
        padding: 14px;
    }

    .summary-cards {
        grid-template-columns: 1fr;
    }

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

    .btn-export {
        justify-content: center;
    }

    .theme-toggle,
    .settings-toggle {
        width: 42px;
        height: 42px;
    }

    .theme-toggle .theme-icon,
    .settings-toggle span {
        font-size: 1.3rem;
    }

    .settings-dropdown-menu {
        right: -50px;
        min-width: 180px;
    }

    .grace-payment-toggle {
        flex-wrap: nowrap;
    }

    .toggle-label {
        font-size: 0.6rem;
    }
}

/* Number input spinner */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
    height: 30px;
}

/* Print styles */
@media print {

    .header-controls,
    .input-section,
    .export-section,
    .btn-primary {
        display: none !important;
    }

    .main-content {
        display: block;
    }

    .results-section {
        box-shadow: none;
        border: 1px solid #ccc;
    }

    body {
        background: white;
        color: black;
    }
}

/* Cost Modal Styles */
.cost-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.cost-modal {
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 450px;
    padding: 0;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

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

.cost-modal h3 {
    font-size: 1.25rem;
    color: var(--text-primary);
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    margin: 0;
}

.cost-modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    /* Allow max height */
    overflow-y: auto;
    /* Enable vertical scroll */
    overflow-x: hidden;
    /* Prevent horizontal scroll */
}

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

.cost-modal-body .form-group:last-child {
    margin-bottom: 0;
}

.cost-modal-body label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.cost-modal-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    color: var(--text-primary);
    background: var(--input-bg);
    transition: var(--transition);
}

.cost-modal-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

.cost-modal-input::placeholder {
    color: var(--text-muted);
}

.cost-modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

.cost-modal-footer button {
    padding: 0.65rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.cost-modal-footer .btn-cancel {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.cost-modal-footer .btn-cancel:hover {
    background: var(--bg-secondary);
}

.cost-modal-footer .btn-confirm {
    background: var(--accent-color);
    color: white;
}

.cost-modal-footer .btn-confirm:hover {
    background: var(--accent-hover);
}

/* Updated cost item display (no input fields) */
.cost-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 0.5rem;
}

.cost-item .cost-name {
    flex: 1;
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
}

.cost-item .cost-amount {
    font-size: 0.95rem;
    color: var(--accent-color);
    font-weight: 600;
    min-width: 120px;
    text-align: right;
}

.cost-item .btn-remove {
    background: transparent;
    border: none;
    color: var(--error-color);
    font-size: 1.5rem;
    line-height: 1;
    padding: 0;
    width: 24px;
    height: 24px;
    cursor: pointer;
    transition: var(--transition);
    border-radius: 4px;
}

.cost-item .btn-remove:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Footer Styles */
.footer {
    text-align: center;
    padding: 2rem 1rem;
    margin-top: 3rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.footer p {
    margin: 0.5rem 0;
}

.footer .disclaimer {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Language Selection Modal */
.language-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    animation: fadeIn 0.3s ease;
    backdrop-filter: blur(5px);
}

.language-modal {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    text-align: center;
    animation: slideUp 0.4s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }

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

.language-modal h2 {
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 30px;
    font-weight: 600;
    line-height: 1.4;
}

.language-options {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.lang-btn {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px 30px;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.lang-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.lang-btn.suggested {
    border-color: var(--accent-color);
    background: linear-gradient(135deg, rgba(67, 97, 238, 0.05), rgba(67, 97, 238, 0.1));
}

.lang-btn .lang-flag {
    font-size: 2rem;
    line-height: 1;
}

.lang-btn .lang-name {
    flex: 1;
    text-align: left;
    font-weight: 600;
}

.lang-btn .lang-hint {
    font-size: 0.8rem;
    color: var(--accent-color);
    font-weight: 500;
    padding: 4px 12px;
    background: rgba(67, 97, 238, 0.1);
    border-radius: 12px;
}

.lang-btn:hover .lang-hint {
    color: white;
    background: rgba(255, 255, 255, 0.2);
}

@media (max-width: 480px) {
    .language-modal {
        padding: 30px 20px;
    }

    .language-modal h2 {
        font-size: 1.2rem;
        margin-bottom: 20px;
    }

    .lang-btn {
        padding: 16px 20px;
    }

    .lang-btn .lang-flag {
        font-size: 1.5rem;
    }

    .lang-btn .lang-name {
        font-size: 1rem;
    }
}

/* Cost Modal New Styles */
.cost-payment-mode {
    margin-bottom: 20px;
}

.mode-options {
    display: flex;
    gap: 10px;
}

.mode-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.mode-option:hover {
    border-color: var(--accent-color);
}

.mode-option.selected {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.mode-option input {
    display: none;
}

.cost-finance-details {
    display: none;
    background: var(--bg-primary);
    padding: 15px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.cost-finance-details.active {
    display: block;
    animation: fadeIn 0.3s;
}

.payment-mode-badge {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

.payment-mode-badge.financed {
    background: rgba(67, 97, 238, 0.1);
    color: var(--accent-color);
    border-color: rgba(67, 97, 238, 0.2);
}

/* Custom Number Input Spinners */
/* Hide default spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    /* Firefox */
}

.spinner-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.spinner-wrapper input {
    flex: 1;
    padding-right: 32px;
    /* Space for buttons */
}

.spinner-btns {
    position: absolute;
    right: 2px;
    top: 2px;
    bottom: 2px;
    display: flex;
    flex-direction: column;
    width: 24px;
    gap: 1px;
}

.spinner-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    font-size: 10px;
    padding: 0;
    margin: 0;
    line-height: 1;
}

.spinner-btn:first-child {
    border-top-right-radius: 4px;
    margin-bottom: 0px;
}

.spinner-btn:last-child {
    border-bottom-right-radius: 4px;
}

.spinner-btn:hover {
    background: var(--accent-color);
    color: white;
}

.spinner-btn:active {
    background: var(--accent-hover);
}

/* Ensure wrapper works in compact rows */
.input-inline .spinner-wrapper {
    width: auto;
    flex: 1;
}

.input-inline .spinner-wrapper input {
    width: 100%;
    padding-right: 24px;
}

.input-inline .spinner-btns {
    width: 18px;
}

/* Theme adaptation is handled by CSS variables (var(--bg-secondary), var(--accent-color)) */

/* Chart Scroll Container */
.chart-scroll-container {
    overflow: auto;
    /* Allow both vertical and horizontal scroll */
    max-height: 500px;
    /* Limit visible height to show vertical scrollbar */
    width: 100%;
    max-width: 100%;
    /* Ensure strict containment */
    position: relative;
    /* Clean style - wrapper handles card look */
    cursor: grab;
}

.chart-scroll-container:active {
    cursor: grabbing;
}

.chart-scroll-container canvas {
    min-width: 100%;
}

/* Scrollbar styling - Unified with Table */
.chart-scroll-container::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.chart-scroll-container::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 4px;
}

.chart-scroll-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.chart-scroll-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Results Header Actions */
.results-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}



/* History Dropdown */
.history-dropdown {
    position: relative;
}

.history-toggle {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--theme-btn-bg);
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
}

.history-toggle:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.history-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 280px;
    max-height: 350px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--transition);
    overflow: hidden;
}

.history-dropdown.active .history-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--text-primary);
}

.btn-clear-history {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    opacity: 0.6;
    transition: var(--transition);
}

.btn-clear-history:hover {
    opacity: 1;
    transform: scale(1.2);
}

.history-list {
    max-height: 280px;
    overflow-y: auto;
    padding: 8px;
}

.history-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
    font-size: 0.9rem;
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.history-item-type {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--accent-color);
}

.history-item-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.history-item-details {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.history-item-amount {
    font-weight: 600;
    color: var(--text-primary);
}

/* History Item Layout */
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: 6px;
    transition: var(--transition);
    margin-bottom: 4px;
    border: 1px solid transparent;
}

.history-item:hover {
    background: var(--bg-card);
    border-color: var(--border-color);
}

.history-item-main {
    flex: 1;
    cursor: pointer;
}

/* History Action Buttons */
.history-item-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.history-item:hover .history-item-actions {
    opacity: 1;
}

.history-action-btn {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 4px;
    background: var(--bg-primary);
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.history-action-btn:hover {
    background: var(--accent-color);
    color: white;
    transform: scale(1.1);
}

.history-action-btn.delete:hover {
    background: var(--error-color);
}

/* Toast Notification */
.toast-notification {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 9999;
}

.toast-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Real-time Validation Styles */
.input-error {
    border-color: var(--error-color) !important;
    animation: shake 0.3s ease-in-out;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.input-section .form-group {
    position: relative;
}

.error-tooltip {
    position: absolute;
    bottom: -22px;
    left: 0;
    font-size: 0.75rem;
    color: var(--error-color);
    background: var(--bg-card);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--error-color);
    white-space: nowrap;
    z-index: 10;
    animation: fadeIn 0.2s ease;
}

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

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

.input-section .form-group.has-error .input-with-unit input,
.input-section .form-group.has-error input,
.input-section .form-group.has-error select {
    border-color: var(--error-color);
}