:root {
    --bg: #f5f5f7;
    --card: #ffffff;
    --text: #1c1c1e;
    --text-secondary: #6e6e73;
    --font-scale: 0.95;
    --green: #34c759;
    --red: #ff3b30;
    --blue: #007aff;
    --purple: #af52de;
    --orange: #ff9500;
    --border: #e5e5ea;
    --paid-bg: #e8f5e9;
    --input-bg: #ffffff;
    --summary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --section-bg: #f2f2f7;
    --modal-bg: rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] {
    --bg: #1c1c1e;
    --card: #2c2c2e;
    --text: #f5f5f7;
    --text-secondary: #8e8e93;
    --green: #30d158;
    --red: #ff453a;
    --blue: #0a84ff;
    --purple: #bf5af2;
    --orange: #ff9f0a;
    --border: #3a3a3c;
    --paid-bg: #1c3a1e;
    --input-bg: #3a3a3c;
    --summary-gradient: linear-gradient(135deg, #5856d6 0%, #af52de 100%);
    --section-bg: #2c2c2e;
    --modal-bg: rgba(0, 0, 0, 0.6);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    padding-bottom: 10px;
    transition: background 0.3s, color 0.3s;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
}

#bottomContainer {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
    padding-top: 0px;
}

header {
    position: sticky;
    top: 0;
    background: rgba(var(--bg-rgb, 245, 245, 247), 0.95);
    backdrop-filter: blur(10px);
    z-index: 100;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    transition: background 0.3s, border-color 0.3s;
}

[data-theme="dark"] header {
    background: rgba(28, 28, 30, 0.95);
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: nowrap;
    overflow: hidden;
}

h1 {
    font-size: calc(20px * var(--font-scale));
    font-weight: 700;
    letter-spacing: -0.5px;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.dropdown {
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: calc(14px * var(--font-scale));
    font-weight: 600;
    cursor: pointer;
    outline: none;
    min-width: 60px;
    flex-shrink: 0;
    transition: background 0.3s, color 0.3s, border-color 0.3s;
}

.icon-btn-top {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: calc(16px * var(--font-scale));
    flex-shrink: 0;
    transition: all 0.2s;
}

.icon-btn-top:hover {
    background: var(--bg);
}

.card {
    background: var(--card);
    border-radius: 16px;
    padding: 0;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: background 0.3s, color 0.3s;
    overflow: hidden;
}

#excludedFootnote {
    background: var(--card);
    border-radius: 16px;
    padding: 0;
    margin-top: 16px;
    margin-bottom: 5px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: background 0.3s, color 0.3s;
    overflow: hidden;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    cursor: pointer;
    user-select: none;
    background: var(--section-bg);
    transition: background 0.2s;
}

.section-header:active {
    background: var(--border);
}

.section-title {
    font-size: calc(20px * var(--font-scale));
    font-weight: 700;
    padding-left: 8px;
    border-left: 4px solid var(--blue);
    flex: 1;
    color: var(--text);
    transition: color 0.3s;
}

.section-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.collapse-icon {
    font-size: calc(14px * var(--font-scale));
    color: var(--text-secondary);
    margin-right: 8px;
    transition: transform 0.3s;
}

.collapse-icon.collapsed {
    transform: rotate(-90deg);
}

.section-content {
    padding: 0 16px 16px 16px;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 2000px;
    opacity: 1;
    overflow: hidden;
}

.section-content.collapsed {
    max-height: 0;
    opacity: 0;
    padding: 0 16px;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: calc(16px * var(--font-scale));
    transition: background 0.3s, border-color 0.3s;
}

.item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    font-size: calc(16px * var(--font-scale));
    transition: background 0.2s;
    gap: 12px;
}

.item:last-child {
    border-bottom: none;
}

.item.included {
    background: var(--paid-bg);
}

.item.included .amount-display {
    color: var(--green);
    font-weight: 700;
}

.item-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.checkbox {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 2px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(14px * var(--font-scale));
    flex-shrink: 0;
    transition: all 0.2s;
}

.checkbox.checked {
    background: var(--green);
    border-color: var(--green);
    color: white;
}

.emoji {
    font-size: calc(20px * var(--font-scale));
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.item-name {
    font-weight: 500;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
    transition: color 0.3s;
}

.item-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: auto;
}

.amount-input {
    width: 80px;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font-size: calc(15px * var(--font-scale));
    font-weight: 600;
    text-align: right;
    outline: none;
    transition: background 0.3s, color 0.3s, border-color 0.3s;
}

.amount-input:focus {
    border-color: var(--blue);
}

.period-select {
    padding: 6px 6px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: calc(12px * var(--font-scale));
    font-weight: 500;
    outline: none;
    cursor: pointer;
    transition: background 0.3s, color 0.3s, border-color 0.3s;
}

.delete-btn {
    color: var(--red);
    font-size: calc(20px * var(--font-scale));
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    padding: 0 4px;
    flex-shrink: 0;
}

.item:hover .delete-btn {
    opacity: 1;
}

.total-row {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding: 12px 8px;
    margin-top: 8px;
    font-weight: 700;
    font-size: calc(16px * var(--font-scale));
    color: var(--text);
    transition: color 0.3s, border-color 0.3s;
}

.total-amount {
    font-weight: 700;
    font-size: calc(17px * var(--font-scale));
}

.total-period {
    padding: 4px 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: calc(13px * var(--font-scale));
    font-weight: 600;
    outline: none;
    cursor: pointer;
    transition: background 0.3s, color 0.3s, border-color 0.3s;
}

.summary-box {
    background: var(--summary-gradient);
    color: white;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 8px;
    margin-top:25px;
}

.summary-box .section-title {
    border-left-color: rgba(255, 255, 255, 0.5);
    color: white;
}

.summary-box .item {
    border-bottom-color: rgba(255, 255, 255, 0.2);
}

.summary-box .item-name {
    color: white;
}

.summary-box .amount-display {
    color: white;
}

.summary-box .amount-input {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    color: white;
}

.summary-box .amount-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.summary-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.25);
    margin: 12px 0;
    display: none;
}

.excluded-star {
    color: var(--red);
    font-weight: 800;
}

.leftover-positive {
    color: var(--green);
    font-weight: 700;
}

.leftover-negative {
    color: var(--red);
    font-weight: 700;
}

.add-btn {
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    border: 2px dashed var(--border);
    background: transparent;
    border-radius: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    transition: color 0.3s, border-color 0.3s;
}

.add-section-btn {
    width: 100%;
    padding: 16px;
    margin-bottom: 16px;
    border: 2px dashed var(--blue);
    background: rgba(0, 122, 255, 0.05);
    border-radius: 16px;
    color: var(--blue);
    font-weight: 700;
    font-size: calc(16px * var(--font-scale));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.3s, color 0.3s;
}

.hidden-file {
    display: none;
}

.note {
    font-size: calc(13px * var(--font-scale));
    color: var(--text-secondary);
    padding: 8px;
    font-style: italic;
    transition: color 0.3s;
}
.action-bar {
    display: flex;
    justify-content: space-between; /* left + right */
    align-items: center;
    padding: 8px 0px; /* slightly reduced side gap */
}

.action-bar-left {
    display: flex;
    gap: 12px;
    align-items: center; /* fixed (was invalid 'left') */
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: calc(15px * var(--font-scale));
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    background: var(--bg);
}

.github-btn {
    width: 40px;
    height: 36px;

    border-radius: 12px;
    background: var(--card);
    border: 1px solid var(--border);

    display: flex;
    align-items: center;
    justify-content: center;

    cursor: pointer;
    color: var(--text);
    text-decoration: none;

    transition: all 0.2s;
    flex-shrink: 0;
}

.github-btn:hover {
    background: var(--bg);
    transform: scale(1.05);
}

.github-btn:active {
    transform: scale(0.95);
}

.github-btn.hidden {
    display: none;
}

/* Modal Styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--modal-bg);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--card);
    border-radius: 20px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlide 0.3s ease;
}

#settingsModal .modal {
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@keyframes modalSlide {
    from {
        transform: translateY(30px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-title {
    font-size: calc(20px * var(--font-scale));
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text);
}

.modal-field {
    margin-bottom: 16px;
}

.modal-label {
    font-size: calc(14px * var(--font-scale));
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: block;
}

.modal-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font-size: calc(16px * var(--font-scale));
    outline: none;
    transition: border-color 0.2s;
}

.modal-input:focus {
    border-color: var(--blue);
}

.color-presets {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.color-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
}

.color-dot:hover {
    transform: scale(1.1);
}

.color-dot.selected {
    border-color: var(--text);
    transform: scale(1.15);
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
}

.modal-btn {
    flex: 1;
    padding: 14px;
    border-radius: 12px;
    border: none;
    font-size: calc(16px * var(--font-scale));
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-btn-primary {
    background: var(--blue);
    color: white;
}

.modal-btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

/* Settings Toggle Switch */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.toggle-row:last-child {
    border-bottom: none;
}

.toggle-label {
    font-size: calc(15px * var(--font-scale));
    font-weight: 500;
    color: var(--text);
}

.toggle-desc {
    font-size: calc(12px * var(--font-scale));
    color: var(--text-secondary);
    margin-top: 2px;
}

.toggle-switch {
    width: 50px;
    height: 28px;
    border-radius: 14px;
    background: var(--border);
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
    flex-shrink: 0;
}

.toggle-switch.active {
    background: var(--green);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch.active::after {
    transform: translateX(22px);
}

/* Section breakdown in summary */
.breakdown-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: calc(15px * var(--font-scale));
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.range-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
}

.range-row input[type="range"] {
    width: 100%;
}

.range-value {
    min-width: 52px;
    text-align: right;
    font-weight: 700;
    color: var(--text);
    font-size: calc(14px * var(--font-scale));
}

.breakdown-item:last-child {
    border-bottom: none;
}

.breakdown-name {
    display: flex;
    align-items: center;
    gap: 8px;
}

.breakdown-amount {
    font-weight: 600;
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    #bottomContainer {
        padding: 10px;
        padding-top: 0px;
    }

    h1 {
        font-size: calc(18px * var(--font-scale));
    }

    .dropdown {
        font-size: calc(13px * var(--font-scale));
        padding: 5px 8px;
    }

    .icon-btn-top {
        width: 30px;
        height: 30px;
        font-size: calc(14px * var(--font-scale));
    }

    .item {
        font-size: calc(14px * var(--font-scale));
        padding: 8px 6px;
    }

    .amount-input {
        width: 65px;
        font-size: calc(14px * var(--font-scale));
    }

    .period-select {
        font-size: calc(11px * var(--font-scale));
        padding: 5px 4px;
    }

    .emoji {
        font-size: calc(18px * var(--font-scale));
        width: 22px;
    }

    .section-title {
        font-size: calc(18px * var(--font-scale));
    }

    .action-btn {
        padding: 8px 14px;
        font-size: calc(14px * var(--font-scale));
    }

    .modal {
        padding: 20px;
    }

    .modal-title {
        font-size: calc(18px * var(--font-scale));
    }
}