/* ============================================================
   CSS VARIABLES – THEMES
   ============================================================ */
:root {
    --primary: #3b82f6;
    --primary-light: #60a5fa;
    --danger-color: #ef4444;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
}

/* Dark Theme (default) */
.theme-dark {
    --bg-page: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --bg-hover: #273447;
    --border: #334155;
    --text-1: #f1f5f9;
    --text-2: #94a3b8;
    --text-muted: #64748b;
}

/* Light Theme */
.theme-light {
    --bg-page: #f1f5f9;
    --bg-card: #ffffff;
    --bg-input: #f8fafc;
    --bg-hover: #e2e8f0;
    --border: #cbd5e1;
    --text-1: #0f172a;
    --text-2: #475569;
    --text-muted: #94a3b8;
}

/* Green Theme */
.theme-green {
    --bg-page: #052e16;
    --bg-card: #14532d;
    --bg-input: #166534;
    --bg-hover: #15803d;
    --border: #166534;
    --text-1: #f0fdf4;
    --text-2: #86efac;
    --text-muted: #4ade80;
}

/* Pink Theme */
.theme-pink {
    --bg-page: #4a0020;
    --bg-card: #831843;
    --bg-input: #9d174d;
    --bg-hover: #be185d;
    --border: #9d174d;
    --text-1: #fdf2f8;
    --text-2: #f9a8d4;
    --text-muted: #f472b6;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-page);
    color: var(--text-1);
    font-size: 15px;
    line-height: 1.5;
    /* Mobile-only: centre and cap at phone width */
    display: flex;
    justify-content: center;
}

#app-content,
.auth-wrap {
    width: 100%;
    max-width: 480px;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    cursor: pointer;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: inherit;
}

input,
select,
textarea {
    font-family: inherit;
    font-size: 0.9rem;
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    color: var(--text-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
}

textarea {
    resize: vertical;
}

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden {
    display: none !important;
}

.text-danger {
    color: var(--danger-color) !important;
}

.text-success {
    color: var(--success-color) !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

/* ============================================================
   LOADER
   ============================================================ */
.page-loader {
    position: fixed;
    inset: 0;
    background: var(--bg-page);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================================
   AUTH PAGE
   ============================================================ */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px 28px;
    width: 100%;
    max-width: 400px;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.auth-logo i {
    font-size: 2rem;
    color: var(--primary);
}

.auth-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.auth-logo h1 span {
    color: var(--primary);
}

.auth-sub {
    color: var(--text-2);
    margin-bottom: 28px;
    font-size: 0.9rem;
}

.error-msg {
    color: var(--danger-color);
    font-size: 0.85rem;
    min-height: 20px;
    margin-bottom: 8px;
}

/* ============================================================
   FORMS (shared)
   ============================================================ */
.input-group {
    margin-bottom: 16px;
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .input-group {
    flex: 1;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition);
    cursor: pointer;
    border: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-light);
}

.btn-danger {
    background: var(--danger-color);
    color: #fff;
}

.btn-danger:hover {
    opacity: 0.85;
}

.btn-outline {
    background: transparent;
    color: var(--text-2);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: var(--bg-hover);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.82rem;
}

.btn-block {
    width: 100%;
    margin-top: 8px;
}

.btn:disabled {
    opacity: 0.5;
    pointer-events: none;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text-2);
    background: transparent;
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-1);
}

/* ============================================================
   APP HEADER
   ============================================================ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.avatar {
    width: 34px;
    height: 34px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    flex-shrink: 0;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-1);
}

/* ============================================================
   MAIN SCROLL AREA
   ============================================================ */
.main-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 80px;
    /* room for bottom-nav */
}

/* ============================================================
   SECTION HEADER
   ============================================================ */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.month-input {
    padding: 5px 8px;
    font-size: 0.82rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-1);
    width: auto;
}

/* ============================================================
   STATS ROW
   ============================================================ */
.stats-row {
    display: flex;
    gap: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 16px;
}

.stat-box {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    border-right: 1px solid var(--border);
}

.stat-box:last-child {
    border-right: none;
}

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.04em;
}

.stat-val {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-1);
}

/* ============================================================
   LIST ITEMS (expenses + notes share this)
   ============================================================ */
.list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.list-item-main {
    flex: 1;
    min-width: 0;
}

.item-title {
    display: block;
    font-weight: 600;
    font-size: 0.92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-sub {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-amount {
    font-weight: 700;
    font-size: 0.92rem;
    white-space: nowrap;
    color: var(--text-1);
    flex-shrink: 0;
}

.item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.item-actions .icon-btn {
    width: 30px;
    height: 30px;
    font-size: 1rem;
}

/* Note specific */
.note-item {
    align-items: flex-start;
}

.note-badges {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.badge {
    font-size: 0.68rem;
    padding: 2px 7px;
    border-radius: 99px;
    font-weight: 600;
}

.badge-status {
    background: var(--bg-hover);
    color: var(--text-2);
}

.badge-priority {
    background: transparent;
}

.item-desc {
    font-size: 0.88rem;
    color: var(--text-1);
    white-space: pre-wrap;
    word-break: break-word;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.8;
    padding: 36px 16px;
}

.empty-state i {
    font-size: 2.5rem;
    opacity: 0.4;
    display: block;
    margin-bottom: 8px;
}

/* ============================================================
   LIST FOOTER
   ============================================================ */
.list-footer {
    text-align: center;
    margin-top: 12px;
}

/* ============================================================
   FLOATING ACTION BUTTON
   ============================================================ */
.fab {
    position: fixed;
    bottom: 70px;
    /* above bottom nav */
    right: calc(50% - 240px + 16px);
    /* aligned to right of 480px container */
    width: 52px;
    height: 52px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.5);
    transition: var(--transition);
    z-index: 200;
}

.fab:hover {
    transform: scale(1.1);
    background: var(--primary-light);
}

/* Fallback for small screens where 50% calc might go off */
@media (max-width: 480px) {
    .fab {
        right: 16px;
    }
}

/* ============================================================
   BOTTOM NAVIGATION
   ============================================================ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 150;
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 0 8px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: var(--transition);
    background: transparent;
    border: none;
    cursor: pointer;
}

.bottom-nav-item i {
    font-size: 1.3rem;
}

.bottom-nav-item.active {
    color: var(--primary);
}

.bottom-nav-item:hover {
    color: var(--primary);
    background: var(--bg-hover);
}

/* ============================================================
   MODALS
   ============================================================ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 500;
    align-items: flex-end;
    /* slide up from bottom on mobile */
    justify-content: center;
    padding: 0;
    backdrop-filter: blur(3px);
}

.modal.open {
    display: flex;
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(40px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 92vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

.modal-sub {
    font-size: 0.85rem;
    color: var(--text-2);
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* ============================================================
   THEME PICKER
   ============================================================ */
.theme-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 8px;
}

.theme-opt {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-1);
    font-size: 0.88rem;
    font-weight: 600;
    transition: var(--transition);
}

.theme-opt:hover {
    border-color: var(--primary);
}

.theme-opt.active {
    border-color: var(--primary);
    background: var(--bg-hover);
}

.theme-swatch {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ============================================================
   ADMIN VIEW
   ============================================================ */
.admin-user-row {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.admin-user-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.admin-user-info strong {
    font-size: 0.95rem;
}

.admin-user-info span {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.role-badge {
    display: inline-block;
    font-size: 0.68rem;
    padding: 2px 8px;
    border-radius: 99px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    width: fit-content;
}

.role-badge.admin {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger-color);
}

.role-badge.user {
    background: rgba(59, 130, 246, 0.15);
    color: var(--primary);
}

/* ============================================================
   VIEW SECTION
   ============================================================ */
.view-section {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}