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

:root {
    --bg: #f0f2f5;
    --bg-dark: #e4e6eb;
    --surface: #ffffff;
    --primary: #128c7e;
    --primary-dark: #0e6b5e;
    --accent: #25d366;
    --text: #1a1a1a;
    --text-secondary: #65676b;
    --text-light: #ffffff;
    --border: #e0e0e0;
    --danger: #e74c3c;
    --bubble-user: #dcf8c6;
    --bubble-system: #ffffff;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --radius: 12px;
    --nav-height: 56px;
    --input-height: 60px;
    --header-height: 52px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ===== Views ===== */
.view {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
}

/* App views sit above nav */
#view-entries,
#view-dashboard {
    bottom: var(--nav-height);
}

.hidden {
    display: none !important;
}

/* ===== Login ===== */
.login-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-logo {
    font-size: 36px;
    font-weight: 700;
    color: var(--text-light);
    margin-bottom: 8px;
    letter-spacing: -1px;
}

.login-subtitle {
    color: rgba(255,255,255,0.8);
    margin-bottom: 32px;
    font-size: 14px;
}

.pin-input-wrap {
    width: 100%;
    max-width: 240px;
    margin-bottom: 16px;
}

.pin-input-wrap input {
    width: 100%;
    padding: 14px 20px;
    font-size: 24px;
    text-align: center;
    border: none;
    border-radius: var(--radius);
    background: rgba(255,255,255,0.95);
    color: var(--text);
    letter-spacing: 8px;
    outline: none;
}

.pin-input-wrap input:focus {
    box-shadow: 0 0 0 3px rgba(255,255,255,0.4);
}

.btn-primary {
    width: 100%;
    max-width: 240px;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
    background: var(--text-light);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
}

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

.error-text {
    color: #ffcccc;
    font-size: 13px;
    margin-top: 12px;
    min-height: 20px;
}

/* ===== Google Sign-In ===== */
.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    max-width: 280px;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 500;
    color: #333;
    background: #ffffff;
    border: none;
    border-radius: var(--radius);
    text-decoration: none;
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.1s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    margin-bottom: 16px;
}

.btn-google:hover {
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

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

.btn-google svg {
    flex-shrink: 0;
}

/* ===== Setup & Storage Options ===== */
.storage-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 280px;
    margin-top: 16px;
}

.storage-option {
    background: rgba(255,255,255,0.95);
    border: 2px solid transparent;
    border-radius: var(--radius);
    padding: 14px 16px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
}

.storage-option:hover, .storage-option:active {
    border-color: var(--accent);
    transform: scale(1.02);
}

.storage-icon {
    font-size: 20px;
    margin-bottom: 4px;
}

.storage-label {
    font-weight: 600;
    color: var(--text);
    font-size: 14px;
}

.storage-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ===== Header Settings Button ===== */
.btn-signout {
    display: inline-block;
    background: rgba(255,255,255,0.2);
    border: none;
    color: var(--text-light) !important;
    font-size: 11px;
    cursor: pointer;
    padding: 5px 12px;
    border-radius: 16px;
    margin-left: 8px;
    text-decoration: none;
    line-height: 1;
}

.btn-signout:hover {
    background: rgba(255,255,255,0.35);
}

.btn-signout:active {
    background: rgba(255,255,255,0.4);
}

.header-actions {
    display: flex;
    align-items: center;
}

/* ===== App Header ===== */
.app-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--primary);
    color: var(--text-light);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 18px;
    font-weight: 600;
}

.total-badge {
    font-size: 13px;
    font-weight: 600;
    background: rgba(255,255,255,0.2);
    padding: 4px 10px;
    border-radius: 20px;
}

/* ===== Entries List ===== */
.entries-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    padding-bottom: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.placeholder-text {
    text-align: center;
    color: var(--text-secondary);
    margin: auto;
    line-height: 1.6;
}

.placeholder-text small {
    color: #999;
}

/* Entry Bubbles */
.entry-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    animation: fadeInUp 0.2s ease;
}

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

.entry-bubble.user {
    align-self: flex-end;
    background: var(--bubble-user);
    border-bottom-right-radius: 4px;
}

.entry-bubble.system {
    align-self: flex-start;
    background: var(--bubble-system);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow);
}

.entry-bubble.error {
    align-self: flex-start;
    background: #ffeaea;
    border-bottom-left-radius: 4px;
    color: var(--danger);
}

.entry-bubble .bubble-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: right;
}

.entry-bubble .bubble-category {
    font-size: 11px;
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 2px;
}

.entry-bubble .bubble-amount {
    font-weight: 700;
    color: var(--primary-dark);
}

.entry-bubble .bubble-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    border: none;
    background: none;
    color: #ccc;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    border-radius: 50%;
    display: none;
}

.entry-bubble.system:hover .bubble-delete {
    display: block;
}

.entry-bubble .bubble-delete:hover {
    color: var(--danger);
    background: rgba(231,76,60,0.1);
}

/* Loading indicator */
.entry-bubble.loading {
    align-self: flex-start;
    background: var(--bubble-system);
    box-shadow: var(--shadow);
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.2s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ===== Input Bar ===== */
.input-bar {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 8px 12px;
    padding-bottom: 8px;
    flex-shrink: 0;
}

.input-bar-inner {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-bar input {
    flex: 1;
    padding: 10px 14px;
    font-size: 15px;
    border: 1.5px solid var(--border);
    border-radius: 24px;
    outline: none;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s;
}

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

.btn-lang {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
}

.btn-lang:active {
    background: var(--bg-dark);
}

.btn-camera, .btn-mic, .btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.btn-camera {
    background: var(--bg);
    color: var(--text-secondary);
}

.btn-camera:hover {
    background: var(--bg-dark);
}

.btn-camera.uploading {
    background: var(--primary);
    color: white;
    animation: pulse 1.5s infinite;
}

.btn-mic {
    background: var(--bg);
    color: var(--text-secondary);
}

.btn-mic:hover {
    background: var(--bg-dark);
}

.btn-mic.recording {
    background: var(--danger);
    color: white;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,0.4); }
    50% { box-shadow: 0 0 0 10px rgba(231,76,60,0); }
}

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

.btn-send:active {
    background: var(--primary-dark);
}

.btn-mic.unsupported {
    display: none;
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    height: var(--nav-height);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: color 0.2s;
    padding: 4px;
}

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

.nav-btn:active {
    background: var(--bg);
}

/* ===== Dashboard ===== */
.dashboard-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 8px;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.summary-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px 12px;
    text-align: center;
    box-shadow: var(--shadow);
}

.card-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.card-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-dark);
}

.section {
    margin-bottom: 20px;
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Category Breakdown */
.category-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-item {
    background: var(--surface);
    border-radius: 8px;
    padding: 10px 14px;
    box-shadow: var(--shadow);
}

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

.category-name {
    font-size: 13px;
    font-weight: 600;
}

.category-amount {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary-dark);
}

.category-bar {
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
}

.category-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.5s ease;
}

/* Recent Entries */
.recent-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.recent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border-radius: 8px;
    padding: 10px 14px;
    box-shadow: var(--shadow);
}

.recent-item-left {
    flex: 1;
    min-width: 0;
}

.recent-item-desc {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recent-item-meta {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.recent-item-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.recent-item-amount {
    font-size: 15px;
    font-weight: 700;
    color: var(--primary-dark);
}

.recent-item-delete {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    color: #ccc;
    cursor: pointer;
    border-radius: 50%;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.recent-item-delete:hover {
    color: var(--danger);
    background: rgba(231,76,60,0.1);
}

.recurring-badge {
    font-size: 10px;
    background: var(--accent);
    color: white;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
    margin-left: 6px;
}

/* Image result items */
.image-result-item {
    padding: 4px 0;
    border-bottom: 1px solid var(--bg);
    font-size: 13px;
}

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

.image-result-item .bubble-category {
    display: inline;
    margin-right: 4px;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Full screen overlays */
#view-login, #view-setup, #view-restore {
    bottom: 0;
    z-index: 10000;
}

/* Backup checkbox */
.backup-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255,255,255,0.85);
    font-size: 13px;
    margin-top: 16px;
    cursor: pointer;
}

.backup-checkbox input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.btn-secondary {
    width: 100%;
    max-width: 280px;
    padding: 12px;
    font-size: 14px;
    color: var(--text-light);
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: var(--radius);
    cursor: pointer;
    margin-top: 16px;
    text-align: center;
}

/* Restore list */
.restore-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 280px;
    margin-top: 16px;
}

.restore-item {
    background: rgba(255,255,255,0.95);
    border: none;
    border-radius: var(--radius);
    padding: 12px 16px;
    text-align: left;
    cursor: pointer;
    color: var(--text);
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.restore-item:hover {
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.restore-item small {
    color: var(--text-secondary);
    font-size: 11px;
}

/* Settings Panel */
.settings-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 20000;
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

.settings-overlay.hidden {
    display: none !important;
}

.settings-panel {
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
}

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

.settings-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.settings-close {
    width: 32px; height: 32px;
    border: none; background: var(--bg);
    border-radius: 50%; font-size: 20px;
    cursor: pointer; color: var(--text-secondary);
}

.settings-body {
    padding: 12px 20px 24px;
}

.settings-section {
    padding: 14px 0;
    border-bottom: 1px solid var(--bg);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.settings-value {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
}

.settings-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
}

.btn-settings-action {
    background: var(--bg);
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    color: var(--primary);
    font-weight: 600;
    width: 100%;
    text-align: center;
}

.btn-settings-action:hover {
    background: var(--bg-dark);
}

.btn-danger {
    display: block;
    background: var(--danger);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    width: 100%;
    text-align: center;
    text-decoration: none;
    font-weight: 600;
}

.btn-danger-small {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 12px;
    cursor: pointer;
    padding: 8px 0;
    text-decoration: underline;
}

/* Backup list in settings */
.backup-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 8px 0;
}

.backup-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 6px;
    font-size: 13px;
}

.backup-delete {
    width: 24px; height: 24px;
    border: none; background: none;
    color: var(--danger); cursor: pointer;
    font-size: 16px; border-radius: 50%;
}

.backup-delete:hover {
    background: rgba(231,76,60,0.1);
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px; height: 24px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #ccc;
    border-radius: 24px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

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

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

/* ===== Responsive ===== */
@media (min-width: 480px) {
    .summary-cards {
        grid-template-columns: repeat(3, 1fr);
    }

    .card-value {
        font-size: 22px;
    }
}

@media (min-width: 768px) {
    #view-entries,
    #view-dashboard,
    .bottom-nav {
        max-width: 480px;
        left: 50%;
        right: auto;
        width: 480px;
        transform: translateX(-50%);
    }

    body {
        background: var(--bg-dark);
    }
}
