:root {
    --primary-color: #007AFF;
    --secondary-color: #5856D6;
    --bg-color: #F2F2F7;
    --card-bg: #FFFFFF;
    --text-main: #000000;
    --text-secondary: #8E8E93;
    --danger-color: #FF3B30;
}

html, body {
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-color);
    margin: 0;
    padding: 0;
    color: var(--text-main);
    -webkit-tap-highlight-color: transparent;
    
    /* Disable global scrolling and rubber-banding */
    overscroll-behavior: none;
    overflow: hidden; 
    height: 100%;
    touch-action: pan-y; /* Allow vertical scroll, block horizontal gestures */
    
    /* Disable selection and long-press menus */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* Input & Textarea Styles */
input[type="text"],
input[type="number"],
input[type="date"],
textarea {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
    background: #F2F2F7;
    color: var(--text-main);
    outline: none;
    transition: all 0.2s ease;
    box-sizing: border-box;
    -webkit-appearance: none;
    line-height: 1.4;
}

input:focus,
textarea:focus {
    background: #FFFFFF;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(0,122,255,0.1);
}

textarea {
    resize: none;
    min-height: 120px;
}

/* Date Input Overrides */
.date-inputs input {
    width: auto;
    flex: 1;
    background: #fff;
    border: 1px solid #ddd;
    font-size: 14px;
    padding: 8px 12px;
}

/* Login Input Overrides */
#login-username {
    margin-bottom: 20px;
    text-align: center; /* Keep center for login aesthetics */
    font-weight: 500;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    height: 100%; /* Full height */
    display: flex;
    flex-direction: column;
    position: relative;
    /* padding-bottom moved to main to allow scrolling */
    background: var(--card-bg);
    touch-action: pan-y; /* Allow vertical scroll */
}

main {
    flex: 1;
    overflow-y: auto; /* Only main content scrolls */
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 20px 20px 100px 20px; /* Add bottom padding here */
}

header {
    background: var(--card-bg);
    padding: 20px 20px 10px;
    /* Removed box-shadow to blend with main */
    /* box-shadow: 0 4px 20px rgba(0,0,0,0.05); */
    border-bottom: 1px solid rgba(0,0,0,0.05);
    z-index: 100;
    position: sticky;
    top: 0;
}

.logo-container {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.header-logo { width: 32px; height: 32px; margin-right: 10px; }
h1 { font-size: 20px; margin: 0; font-weight: 700; }

.tabs {
    display: flex;
    gap: 20px; /* Increased gap for better touch target */
    overflow-x: auto;
    padding-bottom: 0; /* Removed padding */
    height: 40px; /* Fixed height to prevent jitter */
    align-items: center;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    background: none;
    border: none;
    font-size: 16px; /* Unified font size */
    color: var(--text-secondary);
    padding: 0;
    height: 100%; /* Fill height */
    white-space: nowrap;
    position: relative;
    transition: color 0.3s ease; /* Only animate color */
    display: flex;
    align-items: center;
}

.tab.active {
    color: var(--text-main);
    font-weight: 600;
    font-size: 16px; /* Same as inactive */
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--primary-color);
    border-radius: 2px;
}

.total-amount {
    font-size: 32px;
    font-weight: 700;
    margin-top: 15px;
    color: var(--text-main);
}

#date-picker-container {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #f0f0f0;
    animation: fadeIn 0.3s;
}

.date-inputs {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
}

.date-inputs input {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 5px 8px;
    font-family: inherit;
    background: #f9f9f9;
}

/* Removed: main { flex: 1; padding: 20px; overflow-y: auto; } since it's now defined above */

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 50px;
    font-size: 14px;
}

/* Slide Animations */
@keyframes slideOutToLeft {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-50px); opacity: 0; }
}
@keyframes slideInFromRight {
    from { transform: translateX(50px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutToRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(50px); opacity: 0; }
}
@keyframes slideInFromLeft {
    from { transform: translateX(-50px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.slide-out-left {
    animation: slideOutToLeft 0.2s ease-in forwards;
}
.slide-in-right {
    animation: slideInFromRight 0.25s ease-out forwards;
}

.slide-out-right {
    animation: slideOutToRight 0.2s ease-in forwards;
}
.slide-in-left {
    animation: slideInFromLeft 0.25s ease-out forwards;
}

/* List & Item Styles */
.record-list {
    display: flex;
    flex-direction: column;
    padding-bottom: 20px;
    opacity: 1;
    /* transition: opacity 0.2s ease-in-out; Removed to let animation control */
}

.date-header {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 20px 0 8px;
    background: var(--card-bg);
    position: sticky;
    top: -1px; /* Hack to avoid gap */
    z-index: 10;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
}

.record-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid rgba(0,0,0,0.03);
    background: var(--card-bg);
    transition: background-color 0.2s;
}

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

.record-item:active {
    background-color: #f9f9f9;
}

.record-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.category-icon {
    width: 40px;
    height: 40px;
    border-radius: 20px;
    background: #F2F2F7;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    color: #007AFF;
}

.record-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.record-category {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-main);
}

.record-meta {
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.record-amount {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    text-align: center;
}

.empty-state::before {
    content: '📝';
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.5;
    display: block;
}
.record-category { font-weight: 600; font-size: 16px; }
.record-time { font-size: 12px; color: var(--text-secondary); }
.record-suggestion { font-size: 12px; color: var(--primary-color); background: rgba(0,122,255,0.1); padding: 2px 6px; border-radius: 4px; align-self: flex-start; margin-top: 4px; }

.record-right { font-weight: 700; font-size: 18px; }

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}

.modal-overlay.hidden { display: none; }

.modal-card {
    background: var(--card-bg);
    width: 80%;
    max-width: 320px;
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    transform: scale(0.9);
    opacity: 0;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    text-align: center;
}

@keyframes fadeIn { to { opacity: 1; } }
@keyframes popIn { to { transform: scale(1); opacity: 1; } }

.modal-card h3 { margin: 0 0 20px; font-size: 18px; font-weight: 600; }

.actions { display: flex; gap: 12px; margin-top: 20px; }

.btn-primary, .btn-secondary {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s;
}

.btn-primary { background: var(--primary-color); color: white; box-shadow: 0 4px 12px rgba(0,122,255,0.3); }
.btn-secondary { background: #F2F2F7; color: var(--text-main); }
.btn-primary:active, .btn-secondary:active { transform: scale(0.96); }

/* FAB */
#fab-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
    z-index: 1000;
}

.fab {
    width: 64px;
    height: 64px;
    border-radius: 32px;
    background: var(--primary-color);
    color: white;
    border: none;
    box-shadow: 0 8px 20px rgba(0,122,255,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.3s;
    cursor: pointer;
    touch-action: none; /* Prevent browser zooming/scrolling */
    -webkit-user-select: none;
    user-select: none;
}

.fab:active { transform: scale(0.9); }
.fab.listening { transform: scale(1.1); background: #FF3B30; box-shadow: 0 0 0 10px rgba(255, 59, 48, 0.2); }

.secondary-fab {
    width: 48px;
    height: 48px;
    background: white;
    color: var(--text-main);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.spinner {
    width: 40px; height: 40px;
    border: 4px solid #f3f3f3; border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Login specific */
.error-msg { color: var(--danger-color); font-size: 14px; margin-top: 10px; min-height: 20px; }

/* Result Modal Specifics */
.result-card h3 {
    text-align: center;
    font-size: 20px;
    margin-bottom: 24px;
}

.results-list {
    max-height: 350px;
    overflow-y: auto;
    margin-bottom: 20px;
    padding: 0 4px; /* Space for scrollbar */
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

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

.result-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    overflow: hidden;
}

.result-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.result-category {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-suggestion {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-amount {
    font-weight: 700;
    font-size: 18px;
    color: var(--text-main);
    margin-left: 12px;
    flex-shrink: 0;
}

.result-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0 10px;
    margin-top: 10px;
    border-top: 2px dashed rgba(0,0,0,0.1);
}

.result-total-row span:first-child {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 500;
}

.total-price {
    color: var(--text-main);
    font-size: 28px;
    font-weight: 800;
}

.countdown-bar {
    height: 4px;
    background: #F2F2F7;
    border-radius: 2px;
    margin: 10px 0 10px;
    overflow: hidden;
    position: relative;
}

.progress {
    height: 100%;
    background: var(--primary-color);
    width: 100%;
    transition: width linear;
    border-radius: 2px;
}

.auto-save-hint {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    text-align: center;
}

.actions {
    display: flex;
    gap: 12px;
}

.btn-primary {
    background: linear-gradient(135deg, #007AFF, #0056b3);
    color: white;
    box-shadow: 0 4px 15px rgba(0,122,255,0.3);
}

.btn-secondary {
    background: #F2F2F7;
    color: var(--text-secondary);
    font-weight: 500;
}

.hidden { display: none !important; }


/* Action Sheet */
#action-sheet-overlay {
    align-items: flex-end; /* Align to bottom */
    padding: 0;
}

.action-sheet {
    width: 100%;
    background-color: transparent;
    padding: 10px;
    animation: slideUp 0.3s ease-out;
}

.action-sheet-content {
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 10px;
    backdrop-filter: blur(10px);
}

.action-btn {
    width: 100%;
    padding: 16px;
    border: none;
    background: transparent;
    font-size: 18px;
    font-weight: 500;
    color: #007AFF;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    cursor: pointer;
    transition: background 0.2s;
}

.action-btn:last-child {
    border-bottom: none;
}

.action-btn:active {
    background: rgba(0,0,0,0.05);
}

.action-btn.delete-btn {
    color: #FF3B30;
}

.action-btn.cancel-btn {
    background-color: #fff;
    border-radius: 12px;
    color: #007AFF;
    font-weight: 600;
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Edit Modal */
.edit-card {
    width: 90%;
    max-width: 320px;
}

.form-group {
    margin-bottom: 15px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: #666;
    font-size: 14px;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
}

/* Confirm Modal */
.confirm-msg {
    margin: 20px 0 30px;
    font-size: 16px;
    color: var(--text-main);
    line-height: 1.5;
}
