/* ============================================
   TipGenius — CSS Design System
   ============================================ */

/* --- CSS Variables --- */
:root {
    --primary: #1B8A5A;
    --primary-light: #25A66E;
    --primary-dark: #147A4A;
    --accent: #F5C842;
    --accent-light: #FFD96A;
    --bg: #F5F6FA;
    --bg-card: #FFFFFF;
    --text: #1A1A2E;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;
    --border: #E5E7EB;
    --shadow: 0 2px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.10);
    --radius: 16px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --nav-height: 64px;
    --header-height: 56px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    --glass: rgba(255, 255, 255, 0.72);
    --glass-border: rgba(255, 255, 255, 0.3);

    /* Quality colors */
    --quality-bad: #EF4444;
    --quality-ok: #F59E0B;
    --quality-good: #22C55E;
    --quality-great: #1B8A5A;
    --quality-amazing: #F5C842;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
    --bg: #0F1117;
    --bg-card: #1A1D28;
    --text: #F0F0F5;
    --text-secondary: #9CA3AF;
    --text-muted: #6B7280;
    --border: #2D3140;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --glass: rgba(26, 29, 40, 0.8);
    --glass-border: rgba(45, 49, 64, 0.5);
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .screen { animation: none !important; }
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    transition: background var(--transition), color var(--transition);
}

/* --- Header --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    height: var(--header-height);
    background: var(--glass);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background var(--transition), border var(--transition);
}

.app-title {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text);
    user-select: none;
}

.app-title .accent {
    color: var(--primary);
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.dark-mode-toggle {
    background: var(--bg);
    border: 2px solid var(--border);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    transition: all var(--transition-bounce);
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dark-mode-toggle:hover {
    background: var(--border);
    transform: rotate(15deg);
}

.dark-mode-toggle:active {
    transform: scale(0.85) rotate(-15deg);
}

/* --- Main Content --- */
.app-content {
    flex: 1;
    padding: 16px 16px calc(var(--nav-height) + 24px);
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
}

/* --- Screens --- */
.screen {
    display: none;
    animation: screenIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.screen.active {
    display: block;
}

@keyframes screenIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: background var(--transition), box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}

.card:active {
    transform: scale(0.995);
}

/* --- Bill Input --- */
.input-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.bill-input-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--bg);
}

.bill-input-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(27, 138, 90, 0.12);
    transform: scale(1.01);
}

.currency-symbol {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-muted);
}

.bill-input {
    border: none;
    outline: none;
    font-size: 2rem;
    font-weight: 700;
    width: 100%;
    background: transparent;
    color: var(--text);
    font-family: inherit;
}

.bill-input::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

/* Remove number input spinners */
.bill-input::-webkit-inner-spin-button,
.bill-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.bill-input[type=number] {
    -moz-appearance: textfield;
}

/* --- Tip Preset Buttons --- */
.tip-presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 16px;
}

.tip-btn {
    padding: 12px 8px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    min-height: 48px;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}

.tip-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(27, 138, 90, 0.2) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s;
}

.tip-btn:active::before {
    opacity: 1;
}

.tip-btn:hover {
    border-color: var(--primary-light);
    background: rgba(27, 138, 90, 0.05);
}

.tip-btn:active {
    transform: scale(0.94);
}

.tip-btn.active {
    border-color: var(--primary);
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    box-shadow: 0 4px 12px rgba(27, 138, 90, 0.35);
    transform: scale(1);
}

.tip-btn.custom-btn {
    font-size: 0.85rem;
}

/* --- Custom Slider --- */
.custom-slider-wrap {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.custom-slider-wrap.hidden {
    display: none;
}

.slider-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.slider-label span {
    color: var(--primary);
    font-size: 1.1rem;
}

.custom-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--border) 0%);
    outline: none;
    cursor: pointer;
    transition: background 0.1s;
}

.custom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border: 3px solid #fff;
    box-shadow: 0 2px 10px rgba(27, 138, 90, 0.35);
    cursor: pointer;
    transition: transform var(--transition-bounce), box-shadow var(--transition);
}

.custom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 16px rgba(27, 138, 90, 0.45);
}

.custom-slider::-webkit-slider-thumb:active {
    transform: scale(1.25);
    box-shadow: 0 2px 20px rgba(27, 138, 90, 0.5);
}

.custom-slider::-moz-range-thumb {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border: 3px solid #fff;
    box-shadow: 0 2px 10px rgba(27, 138, 90, 0.35);
    cursor: pointer;
}

.custom-slider::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: var(--border);
}

/* --- Tip Quality Indicator --- */
.tip-quality {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 12px;
    border-radius: var(--radius-xs);
    background: var(--bg);
    transition: background var(--transition);
}

.quality-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--quality-good);
    transition: background 0.3s;
}

.quality-text {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: color 0.3s;
}

/* --- Results Card --- */
.results-card {
    padding: 16px 20px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

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

.result-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    transition: color 0.2s, transform var(--transition-bounce);
}

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

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

/* --- Quick Split --- */
.split-quick-card {
    padding: 16px 20px;
}

.split-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.people-selector {
    display: flex;
    align-items: center;
    gap: 12px;
}

.people-btn {
    width: 40px;
    height: 40px;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: var(--bg);
    color: var(--text);
    font-size: 1.3rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    font-family: inherit;
    line-height: 1;
}

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

.people-btn:active {
    transform: scale(0.92);
}

.people-count {
    font-size: 1.2rem;
    font-weight: 700;
    min-width: 24px;
    text-align: center;
    color: var(--text);
}

.per-person-row {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* --- Bottom Navigation --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--glass);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border-top: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 8px;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
    transition: background var(--transition), border var(--transition);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 12px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: all var(--transition);
    min-width: 56px;
    min-height: 48px;
    color: var(--text-muted);
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.nav-btn::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 32px;
    height: 3px;
    border-radius: 2px;
    background: var(--primary);
    transition: transform var(--transition-bounce);
}

.nav-btn:hover {
    background: rgba(27, 138, 90, 0.05);
}

.nav-btn:active {
    transform: scale(0.9);
}

.nav-btn.active {
    color: var(--primary);
}

.nav-btn.active::after {
    transform: translateX(-50%) scaleX(1);
}

.nav-btn.active .nav-label {
    color: var(--primary);
    font-weight: 700;
}

.nav-icon {
    font-size: 1.4rem;
    line-height: 1;
    transition: transform var(--transition-bounce);
}

.nav-btn.active .nav-icon {
    transform: scale(1.1) translateY(-1px);
}

.nav-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: inherit;
}

/* --- Placeholder Screens --- */
.placeholder-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 20px;
    text-align: center;
}

.placeholder-icon {
    font-size: 3rem;
}

.placeholder-content h2 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
}

.placeholder-content p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    max-width: 280px;
}

/* --- Mode Toggle --- */
.mode-toggle-card {
    padding: 8px;
    margin-bottom: 12px;
}

.mode-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.mode-btn {
    flex: 1;
    padding: 10px 12px;
    border: none;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.mode-btn .mode-icon {
    font-size: 1rem;
}

.mode-btn.active {
    background: var(--bg-card);
    color: var(--primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

[data-theme="dark"] .mode-btn.active {
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* --- Reverse Mode --- */
.reverse-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.reverse-tab {
    flex: 1;
    padding: 8px 4px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    min-height: 40px;
    white-space: nowrap;
}

.reverse-tab.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.reverse-panel {
    display: none;
}

.reverse-panel.active {
    display: block;
}

.reverse-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 12px;
    font-style: italic;
}

.reverse-result {
    display: none;
}

.reverse-result.active {
    display: block;
}

.reverse-percent {
    color: var(--primary) !important;
    font-size: 1.4rem !important;
}

/* Budget Breakdown */
.budget-breakdown {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.budget-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.budget-percent {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-secondary);
    min-width: 36px;
    text-align: right;
}

.budget-bar-wrap {
    flex: 1;
    height: 24px;
    background: var(--bg);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.budget-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 12px;
    transition: width 0.4s ease;
    min-width: 0;
}

.budget-amount {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    min-width: 70px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* --- Smart Rounding --- */
.rounding-card {
    padding: 16px 20px;
}

.rounding-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

.rounding-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    color: var(--text-muted);
    transition: transform var(--transition);
}

.rounding-toggle.open .rounding-chevron {
    transform: rotate(180deg);
}

.rounding-chevron {
    display: inline-block;
    font-size: 0.7rem;
    transition: transform var(--transition);
}

.rounding-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.rounding-options.open {
    max-height: 300px;
}

.rounding-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    text-align: left;
    width: 100%;
}

.rounding-option:hover {
    border-color: var(--primary-light);
}

.rounding-option.selected {
    border-color: var(--primary);
    background: rgba(27, 138, 90, 0.06);
}

.rounding-option-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.rounding-option-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
}

.rounding-option-values {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.rounding-diff {
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
    padding: 3px 8px;
    border-radius: 20px;
}

.rounding-diff.save {
    color: #16A34A;
    background: rgba(22, 163, 74, 0.1);
}

.rounding-diff.cost {
    color: #F59E0B;
    background: rgba(245, 158, 11, 0.1);
}

.rounding-diff.zero {
    color: var(--text-muted);
    background: var(--bg);
}

/* ============================================
   Split Screen Styles
   ============================================ */

/* --- Split Tip Section --- */
.split-tip-section {
    margin-top: 16px;
}

.split-tip-section .input-label {
    margin-bottom: 8px;
}

/* --- Split People Header --- */
.split-people-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.split-people-selector .people-count {
    font-size: 1.3rem;
}

/* --- Even Split Actions --- */
.even-split-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.split-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    min-height: 44px;
}

.split-action-btn:hover {
    border-color: var(--primary-light);
    background: rgba(27, 138, 90, 0.05);
}

.split-action-btn:active {
    transform: scale(0.97);
}

.split-action-btn.copied {
    border-color: var(--primary);
    background: rgba(27, 138, 90, 0.1);
    color: var(--primary);
}

/* --- Add Person Button --- */
.add-person-btn {
    padding: 6px 16px;
    border: 2px solid var(--primary);
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.add-person-btn:hover {
    background: var(--primary);
    color: #fff;
}

.add-person-btn:active {
    transform: scale(0.95);
}

/* --- Diners List --- */
.diners-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
}

.diner-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg);
    border-radius: var(--radius-xs);
    transition: background var(--transition);
}

.diner-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.diner-name-input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    padding: 4px 0;
    font-family: inherit;
}

.diner-name-input:focus {
    border-bottom: 2px solid var(--primary);
}

.diner-remove {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.1);
    color: #EF4444;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
    line-height: 1;
}

.diner-remove:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* --- Companion Suggestions --- */
.companion-suggestions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

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

.suggestion-chip {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.suggestion-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* --- Add Item Row --- */
.add-item-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.item-name-input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}

.item-name-input:focus {
    border-color: var(--primary);
}

.item-price-wrap {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 10px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    width: 100px;
    transition: border-color var(--transition);
}

.item-price-wrap:focus-within {
    border-color: var(--primary);
}

.item-price-input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    width: 100%;
    font-family: inherit;
}

.item-price-input::-webkit-inner-spin-button,
.item-price-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.item-price-input[type=number] {
    -moz-appearance: textfield;
}

.add-item-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: var(--radius-xs);
    background: var(--primary);
    color: #fff;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
    line-height: 1;
}

.add-item-btn:hover {
    background: var(--primary-light);
}

.add-item-btn:active {
    transform: scale(0.92);
}

/* --- Items List --- */
.items-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.items-empty {
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
    padding: 16px 0;
    font-style: italic;
}

.item-entry {
    padding: 10px 12px;
    background: var(--bg);
    border-radius: var(--radius-xs);
    transition: background var(--transition);
}

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

.item-entry-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.item-entry-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-entry-price {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.item-remove-btn {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.1);
    color: #EF4444;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    flex-shrink: 0;
    line-height: 1;
}

/* --- Item Assignment Avatars --- */
.item-assign-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.item-assign-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all var(--transition);
}

.item-assign-avatar.assigned {
    border-color: rgba(255,255,255,0.3);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    transform: scale(1.05);
}

.item-assign-avatar:not(.assigned):hover {
    opacity: 0.7;
    transform: scale(1.05);
}

.item-assigned-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
    font-style: italic;
}

/* --- Item Split Row (Tax / Tip side-by-side) --- */
.item-split-row {
    display: flex;
    gap: 12px;
}

.item-split-field {
    flex: 1;
}

/* --- Item Split Summary --- */
.item-summary-person {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.item-summary-person:last-of-type {
    border-bottom: none;
}

.item-summary-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.item-summary-total {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.item-summary-detail {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
    margin-left: 38px;
}

.item-summary-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    margin-left: 38px;
}

.split-copy-person {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.split-copy-person:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.split-venmo-link {
    padding: 4px 10px;
    border: 1px solid #008CFF;
    border-radius: 16px;
    background: rgba(0, 140, 255, 0.05);
    color: #008CFF;
    font-size: 0.72rem;
    font-weight: 700;
    text-decoration: none;
    transition: all var(--transition);
}

.split-venmo-link:hover {
    background: rgba(0, 140, 255, 0.1);
}

.item-summary-grand-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0 0;
    border-top: 2px solid var(--border);
    margin-top: 8px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.item-summary-grand-total span:last-child {
    color: var(--primary);
    font-size: 1.3rem;
}

/* ============================================
   World Tipping Guide Styles
   ============================================ */

/* --- Search Bar --- */
.world-search-card {
    padding: 14px 16px;
}

.world-search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    background: var(--bg);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.world-search-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(27, 138, 90, 0.15);
}

.world-search-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.world-search-input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    font-weight: 500;
    width: 100%;
    font-family: inherit;
}

.world-search-input::placeholder {
    color: var(--text-muted);
}

.world-search-clear {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
    line-height: 1;
}

.world-search-clear:hover {
    background: var(--text-muted);
    color: #fff;
}

.world-filter-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
}

.world-count {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.world-fav-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border: 2px solid var(--border);
    border-radius: 20px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.world-fav-toggle:hover {
    border-color: var(--accent);
}

.world-fav-toggle.active {
    border-color: var(--accent);
    background: rgba(245, 200, 66, 0.1);
    color: var(--text);
}

/* --- Regions --- */
.world-region {
    margin-bottom: 8px;
}

.region-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all var(--transition);
    user-select: none;
}

.region-header:hover {
    background: var(--bg);
}

.region-header:active {
    transform: scale(0.99);
}

.region-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    flex: 1;
}

.region-count {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--bg);
    padding: 2px 10px;
    border-radius: 12px;
}

.region-chevron {
    font-size: 0.6rem;
    color: var(--text-muted);
    transition: transform 0.25s ease;
    display: inline-block;
}

.region-chevron.open {
    transform: rotate(180deg);
}

.region-countries {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
    padding: 0 4px;
}

.region-countries.open {
    max-height: 2000px;
    padding-top: 6px;
}

/* --- Country Cards --- */
.country-card {
    background: var(--bg-card);
    border-radius: var(--radius-xs);
    padding: 12px 14px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    border: 1px solid transparent;
}

.country-card:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow);
}

.country-card:active {
    transform: scale(0.99);
}

.country-card-main {
    display: flex;
    align-items: center;
    gap: 12px;
}

.country-flag {
    font-size: 2rem;
    line-height: 1;
    flex-shrink: 0;
}

.country-card-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.country-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
}

.country-tip-preview {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.country-fav-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: transparent;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
    line-height: 1;
}

.country-fav-btn:hover {
    background: rgba(245, 200, 66, 0.15);
}

.country-fav-btn.active {
    transform: scale(1.1);
}

/* --- Empty State --- */
.world-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 20px;
    text-align: center;
}

.world-empty-icon {
    font-size: 2.5rem;
}

.world-empty p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    max-width: 260px;
}

/* --- Country Detail View --- */
.detail-back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border: none;
    background: none;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    margin-bottom: 8px;
    transition: all var(--transition);
}

.detail-back-btn:hover {
    opacity: 0.7;
}

.detail-back-btn span {
    font-size: 1.2rem;
}

.detail-card {
    padding: 24px 20px;
}

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

.detail-flag {
    font-size: 4rem;
    line-height: 1;
    margin-bottom: 8px;
}

.detail-country-name {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 12px;
}

.detail-fav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    border: 2px solid var(--border);
    border-radius: 24px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.detail-fav-btn:hover {
    border-color: var(--accent);
}

.detail-fav-btn.active {
    border-color: var(--accent);
    background: rgba(245, 200, 66, 0.1);
    color: var(--text);
}

/* --- Service Grid --- */
.detail-services {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 20px;
}

.detail-service-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--bg-card);
    border-radius: var(--radius-xs);
}

.detail-service-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.detail-service-icon {
    font-size: 1.2rem;
    width: 28px;
    text-align: center;
}

.detail-service-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.detail-service-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.detail-service-range {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
}

.detail-service-level {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* --- Detail Sections --- */
.detail-section {
    margin-bottom: 16px;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.detail-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
}

.detail-section-text {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.detail-fun-fact {
    background: rgba(245, 200, 66, 0.08);
    border: 1px solid rgba(245, 200, 66, 0.2);
}

[data-theme="dark"] .detail-fun-fact {
    background: rgba(245, 200, 66, 0.05);
    border-color: rgba(245, 200, 66, 0.15);
}

/* --- Legend --- */
.detail-legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 12px 0;
}

.detail-legend-item {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* ============================================
   Fun Mode Styles
   ============================================ */

/* --- Fun Tabs --- */
.fun-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.fun-tab {
    flex: 1;
    padding: 10px 8px;
    border: none;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.fun-tab.active {
    background: var(--bg-card);
    color: var(--primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

[data-theme="dark"] .fun-tab.active {
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.fun-panel {
    display: none;
    animation: fadeIn 0.25s ease;
}

.fun-panel.active {
    display: block;
}

/* --- Roulette --- */
.roulette-modes-card {
    padding: 12px 16px;
}

.roulette-modes {
    display: flex;
    gap: 6px;
}

.roulette-mode-btn {
    flex: 1;
    padding: 8px 6px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    text-align: center;
}

.roulette-mode-btn.active {
    border-color: var(--primary);
    background: rgba(27, 138, 90, 0.08);
    color: var(--primary);
}

.roulette-mode-btn:hover {
    border-color: var(--primary-light);
}

.roulette-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 20px;
}

.roulette-wheel-wrap {
    position: relative;
    margin-bottom: 20px;
}

.confetti-container {
    position: absolute;
    top: -20px;
    left: -20px;
    right: -20px;
    bottom: -20px;
    pointer-events: none;
    overflow: hidden;
    display: none;
    z-index: 10;
}

.confetto {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    top: 50%;
    left: 50%;
    animation: confettiFall 2s ease-out forwards;
}

@keyframes confettiFall {
    0% {
        transform: translate(-50%, -50%) rotate(0deg) scale(0);
        opacity: 1;
    }
    10% {
        transform: translate(calc(-50% + var(--x, 0px)), calc(-50% + var(--y, 0px))) rotate(180deg) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(calc(-50% + var(--x, 0px)), calc(-50% + 200px)) rotate(720deg) scale(0.5);
        opacity: 0;
    }
}

.confetto:nth-child(odd) { --x: -60px; }
.confetto:nth-child(even) { --x: 60px; }
.confetto:nth-child(3n) { --x: -120px; }
.confetto:nth-child(3n+1) { --x: 120px; }
.confetto:nth-child(5n) { --x: -30px; }
.confetto:nth-child(7n) { --x: 80px; }

#rouletteCanvas {
    display: block;
    border-radius: 50%;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.15));
}

.spin-btn {
    width: 100%;
    padding: 16px 24px;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    box-shadow: 0 4px 16px rgba(27, 138, 90, 0.3);
    position: relative;
    overflow: hidden;
}

.spin-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.15) 50%, transparent 60%);
    transform: translateX(-100%);
    transition: transform 0.6s;
}

.spin-btn:hover::after {
    transform: translateX(100%);
}

.spin-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(27, 138, 90, 0.45);
}

.spin-btn:active {
    transform: translateY(0) scale(0.97);
}

.spin-btn.spinning {
    opacity: 0.7;
    cursor: not-allowed;
    animation: pulse 0.5s ease infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* --- Roulette Result --- */
.roulette-result-card {
    text-align: center;
    padding: 24px 20px;
    animation: fadeIn 0.3s ease;
}

.roulette-result-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-bottom: 20px;
}

.roulette-result-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.roulette-result-percent {
    font-size: 3rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.1;
}

.roulette-result-msg {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.commit-btn {
    width: 100%;
    padding: 14px 24px;
    border: 2px solid var(--primary);
    border-radius: var(--radius-sm);
    background: rgba(27, 138, 90, 0.08);
    color: var(--primary);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.commit-btn:hover {
    background: var(--primary);
    color: #fff;
}

.commit-btn:active {
    transform: scale(0.98);
}

/* --- Rate Server --- */
.rating-card {
    padding: 20px;
}

.rating-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 4px;
}

.rating-subtitle {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.rating-categories {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.rating-category {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rating-cat-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rating-cat-icon {
    font-size: 1.1rem;
}

.rating-cat-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.rating-stars {
    display: flex;
    gap: 6px;
}

.rate-star {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--bg);
    color: var(--border);
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    line-height: 1;
}

.rate-star.active {
    color: #F5C842;
    background: rgba(245, 200, 66, 0.12);
    transform: scale(1.05);
}

.rate-star:hover {
    transform: scale(1.12);
}

.rate-star:active {
    transform: scale(0.95);
}

/* --- Rating Result --- */
.rating-result-card {
    padding: 20px;
}

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

.rating-result-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

.rating-result-percent {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
}

.rating-bar-wrap {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.rating-bar {
    height: 100%;
    border-radius: 4px;
    background: var(--primary);
    transition: width 0.4s ease, background 0.3s ease;
}

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

.rating-tip-label {
    font-size: 0.85rem;
    font-weight: 600;
}

.rating-avg-score {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* --- Generosity Score --- */
.generosity-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 20px;
}

.generosity-ring-wrap {
    position: relative;
    width: 160px;
    height: 160px;
    margin-bottom: 16px;
}

.generosity-ring-svg {
    width: 100%;
    height: 100%;
}

.generosity-score-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.generosity-score-number {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.generosity-score-of {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.generosity-rank {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    text-align: center;
}

.generosity-rank.legendary { color: #F5C842; }
.generosity-rank.above { color: #1B8A5A; }
.generosity-rank.standard { color: #3B82F6; }
.generosity-rank.budget { color: #F59E0B; }

/* --- Generosity Stats --- */
.generosity-stats-card {
    padding: 20px;
}

.generosity-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.generosity-stat-row:last-of-type {
    border-bottom: none;
}

.generosity-stat-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.generosity-stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

.generosity-comparison {
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    padding: 12px 0 4px;
    color: var(--text-secondary);
}

.share-score-btn {
    margin-top: 0;
}

/* --- Fun Toast --- */
.fun-toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: var(--bg);
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 200;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    white-space: nowrap;
    max-width: 90vw;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

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

/* --- Utility --- */
.hidden {
    display: none !important;
}

/* --- Responsive --- */
@media (max-width: 380px) {
    .app-content {
        padding: 12px 12px calc(var(--nav-height) + 16px);
    }
    .bill-input {
        font-size: 1.6rem;
    }
    .total-row .result-value {
        font-size: 1.5rem;
    }
}

@media (min-width: 481px) {
    .app-content {
        padding-top: 24px;
    }
}

/* --- Animations --- */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

.shake {
    animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes countUp {
    0% { opacity: 0.6; transform: scale(0.92) translateY(4px); }
    60% { transform: scale(1.04) translateY(-1px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.result-value.updated {
    animation: countUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

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

@keyframes coinSave {
    0% { transform: scale(1) translateY(0); opacity: 1; }
    50% { transform: scale(1.3) translateY(-8px); opacity: 0.8; }
    100% { transform: scale(0.8) translateY(-30px); opacity: 0; }
}

.coin-save-anim {
    animation: coinSave 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Active button ripple */
@keyframes ripple {
    0% { transform: scale(0); opacity: 0.5; }
    100% { transform: scale(4); opacity: 0; }
}

/* Card entrance stagger */
.screen.active .card {
    animation: slideUp 0.35s cubic-bezier(0.4, 0, 0.2, 1) both;
}
.screen.active .card:nth-child(1) { animation-delay: 0ms; }
.screen.active .card:nth-child(2) { animation-delay: 50ms; }
.screen.active .card:nth-child(3) { animation-delay: 100ms; }
.screen.active .card:nth-child(4) { animation-delay: 150ms; }
.screen.active .card:nth-child(5) { animation-delay: 200ms; }
.screen.active .card:nth-child(6) { animation-delay: 250ms; }

/* ============================================
   Stats & History Styles
   ============================================ */

/* --- Stats Panels --- */
.stats-panel {
    display: none;
    animation: fadeIn 0.25s ease;
}

.stats-panel.active {
    display: block;
}

/* --- Stats Hero Card --- */
.stats-hero-card {
    text-align: center;
    padding: 28px 20px 20px;
    background: linear-gradient(135deg, var(--primary), #22C55E);
    color: #fff;
    position: relative;
    overflow: hidden;
}

.stats-hero-card::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
}

.stats-hero-label {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    opacity: 0.85;
    display: block;
    margin-bottom: 4px;
}

.stats-hero-value {
    font-size: 2.6rem;
    font-weight: 800;
    line-height: 1.1;
    display: block;
    margin-bottom: 16px;
}

.stats-hero-sub {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.stats-hero-sub-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.stats-hero-sub-label {
    font-size: 0.7rem;
    font-weight: 600;
    opacity: 0.75;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-hero-sub-value {
    font-size: 1.2rem;
    font-weight: 700;
}

.stats-hero-sub-divider {
    width: 1px;
    height: 32px;
    background: rgba(255,255,255,0.25);
}

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 8px;
}

.stats-mini-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 12px;
    text-align: center;
    gap: 4px;
}

.stats-mini-card.accent-card {
    grid-column: span 2;
}

.stats-mini-icon {
    font-size: 1.3rem;
    margin-bottom: 2px;
}

.stats-mini-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stats-mini-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* --- Stats Chart --- */
.stats-chart-card {
    padding: 20px 16px;
}

.stats-section-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 16px;
}

.stats-chart-wrap {
    width: 100%;
    min-height: 200px;
}

.stats-chart-wrap canvas {
    width: 100%;
    display: block;
}

/* --- Insights --- */
.stats-insights-card {
    padding: 20px 16px;
}

.insight-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.insight-card:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.insight-card:first-child {
    padding-top: 0;
}

.insight-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.insight-text {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-secondary);
    line-height: 1.4;
}

.stats-empty-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    padding: 16px 0;
    font-style: italic;
}

/* --- History Filter Bar --- */
.stats-filter-card {
    padding: 14px 16px;
}

.stats-search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    background: var(--bg);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.stats-search-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(27, 138, 90, 0.15);
}

.stats-search-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.stats-search-input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 500;
    width: 100%;
    font-family: inherit;
}

.stats-search-input::placeholder {
    color: var(--text-muted);
}

.stats-search-clear {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
    line-height: 1;
}

.stats-search-clear:hover {
    background: var(--text-muted);
    color: #fff;
}

.stats-filter-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.stats-select {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    appearance: auto;
    transition: border-color var(--transition);
}

.stats-select:focus {
    border-color: var(--primary);
    outline: none;
}

.stats-filter-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

.history-count {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-filter-btns {
    display: flex;
    gap: 6px;
}

.stats-icon-btn {
    padding: 6px 14px;
    border: 2px solid var(--border);
    border-radius: 20px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    white-space: nowrap;
}

.stats-icon-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* --- History List --- */
.history-item {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid transparent;
}

.history-item:hover {
    border-color: var(--primary-light);
}

.history-item:active {
    transform: scale(0.99);
}

.history-item-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    gap: 12px;
}

.history-item-left {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1;
}

.history-restaurant {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-date {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
}

.history-item-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
    flex-shrink: 0;
}

.history-bill {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.history-tip-info {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--primary);
}

/* History item actions (slide-open) */
.history-item-actions {
    display: flex;
    gap: 8px;
    padding: 0 16px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease, padding 0.25s ease;
    border-top: 0 solid var(--border);
}

.history-item-actions.open {
    max-height: 60px;
    padding: 10px 16px;
    border-top-width: 1px;
}

.history-edit-btn,
.history-delete-btn {
    padding: 6px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.history-edit-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.history-delete-btn:hover {
    border-color: #EF4444;
    color: #EF4444;
}

/* --- Save Tip Toast --- */
.save-tip-toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-radius: 16px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 200;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    max-width: 90vw;
    pointer-events: none;
}

.save-tip-toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.save-tip-text {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.save-tip-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.save-tip-btn {
    padding: 6px 16px;
    border: none;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    white-space: nowrap;
}

.save-tip-btn:hover {
    background: var(--primary-light);
}

.save-tip-dismiss {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    line-height: 1;
}

.save-tip-dismiss:hover {
    background: var(--border);
}

/* --- Manual Entry Modal --- */
.manual-entry-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.manual-entry-modal.open {
    opacity: 1;
    pointer-events: auto;
}

.manual-entry-content {
    background: var(--bg-card);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px 20px calc(var(--nav-height) + 20px);
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.manual-entry-modal.open .manual-entry-content {
    transform: translateY(0);
}

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

.manual-entry-header h3 {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text);
}

.manual-entry-close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    line-height: 1;
}

.manual-entry-close:hover {
    background: var(--border);
}

.manual-field {
    margin-bottom: 14px;
}

.manual-input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    font-weight: 500;
    font-family: inherit;
    transition: border-color var(--transition);
    box-sizing: border-box;
}

.manual-input:focus {
    border-color: var(--primary);
    outline: none;
}

.manual-input.input-error {
    border-color: #EF4444;
    animation: shake 0.3s ease;
}

.manual-bill-wrap {
    padding: 10px 14px;
}

.manual-row {
    display: flex;
    gap: 12px;
}

.manual-actions {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.manual-save-btn {
    font-size: 1.05rem;
}

.manual-delete-btn {
    width: 100%;
    padding: 12px 24px;
    border: 2px solid #EF4444;
    border-radius: var(--radius-sm);
    background: rgba(239, 68, 68, 0.05);
    color: #EF4444;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.manual-delete-btn:hover {
    background: #EF4444;
    color: #fff;
}

/* --- Stats Notification --- */
.stats-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-80px);
    background: var(--text);
    color: var(--bg);
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 400;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    white-space: nowrap;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

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

/* --- Dark mode overrides --- */
[data-theme="dark"] .stats-hero-card {
    background: linear-gradient(135deg, #0f5e3c, #1a7a52);
}

[data-theme="dark"] .manual-entry-modal {
    background: rgba(0,0,0,0.7);
}

[data-theme="dark"] .save-tip-toast {
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

[data-theme="dark"] .tip-btn.active {
    box-shadow: 0 4px 16px rgba(27, 138, 90, 0.25);
}

[data-theme="dark"] .card {
    border-color: var(--border);
}

[data-theme="dark"] .bill-input-wrap:focus-within {
    box-shadow: 0 0 0 4px rgba(27, 138, 90, 0.2);
}

/* --- Focus Visible (keyboard accessibility) --- */
*:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

button:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

input:focus-visible {
    outline: none;
}

/* --- Swipe Indicator --- */
.swipe-hint {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 40px;
    border-radius: 2px;
    background: var(--primary);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 50;
}

.swipe-hint.left { left: 4px; }
.swipe-hint.right { right: 4px; }
.swipe-hint.visible { opacity: 0.4; }

/* --- People Button Enhancement --- */
.people-btn:active {
    transform: scale(0.85);
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* --- Total Row Glow --- */
.total-row .result-value {
    text-shadow: 0 0 20px rgba(27, 138, 90, 0.15);
}

[data-theme="dark"] .total-row .result-value {
    text-shadow: 0 0 30px rgba(27, 138, 90, 0.3);
}

/* --- Mode Toggle Enhanced --- */
.mode-btn:active {
    transform: scale(0.95);
}

/* --- Commit Button Enhancement --- */
.commit-btn {
    position: relative;
    overflow: hidden;
}

.commit-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 40%, rgba(27, 138, 90, 0.1) 50%, transparent 60%);
    transform: translateX(-100%);
    transition: transform 0.5s;
}

.commit-btn:hover::after {
    transform: translateX(100%);
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

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

/* --- Selection Color --- */
::selection {
    background: rgba(27, 138, 90, 0.2);
    color: var(--text);
}

/* --- Print Hidden --- */
@media print {
    .bottom-nav, .app-header, .save-tip-toast { display: none !important; }
    .app-content { padding-bottom: 0; }
}
