/* style.css — Receipt Snap main stylesheet */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables ── */
:root {
    --primary:     #0147CC;
    --primary-dark:#0138A8;
    --primary-light:#E8EFFF;
    --bg:          #F3F5F8;
    --card:        #FFFFFF;
    --text:        #111827;
    --text-muted:  #6B7280;
    --border:      #E5E7EB;
    --danger:      #DC2626;
    --success:     #16A34A;
    --warning:     #D97706;
    --nav-height:  68px;
    --radius:      12px;
    --radius-sm:   8px;
    --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md:   0 4px 12px rgba(0,0,0,.10);
}

[data-theme="dark"] {
    --bg:         #0F1117;
    --card:       #1C1F2A;
    --text:       #F3F4F6;
    --text-muted: #9CA3AF;
    --border:     #2D3148;
    --primary-light: #1a2a4a;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; }

/* ── Layout ── */
.page-wrap {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 0 calc(var(--nav-height) + 16px);
    min-height: 100vh;
}

/* Full-width admin pages */
.page-wrap.wide { max-width: 900px; }

.page-header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-header h1 {
    font-size: 1.1rem;
    font-weight: 600;
    flex: 1;
}

.page-header .back-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text);
    flex-shrink: 0;
}

.content { padding: 20px; }

/* ── Cards ── */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}

.card-sm { padding: 14px 16px; }

/* ── Bottom Navigation ── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: var(--nav-height);
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
    padding: 8px 0;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.15s;
}

.nav-item.active { color: var(--primary); }

.nav-item svg { width: 22px; height: 22px; }

/* Camera button — highlighted center */
.nav-item.camera-btn {
    color: #fff;
    background: var(--primary);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    flex: none;
    gap: 0;
    font-size: 0;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(1,71,204,.45);
    transition: transform 0.15s, box-shadow 0.15s;
    margin-top: -16px;
}

.nav-item.camera-btn:active {
    transform: scale(0.93);
    box-shadow: 0 2px 8px rgba(1,71,204,.35);
}

/* ── Forms ── */
.form-group { margin-bottom: 16px; }

label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.15s;
    outline: none;
    -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(1,71,204,.12);
}

textarea { resize: vertical; min-height: 80px; }

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline  { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }

.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.88; }

.btn-ghost    { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }

.btn-full { width: 100%; }
.btn-sm { padding: 7px 14px; font-size: 0.82rem; }

/* ── Alerts / Flash messages ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-success { background: #DCFCE7; color: #166534; }
.alert-error   { background: #FEE2E2; color: #991B1B; }
.alert-info    { background: #DBEAFE; color: #1E40AF; }

[data-theme="dark"] .alert-success { background: #14532D33; color: #86EFAC; }
[data-theme="dark"] .alert-error   { background: #7F1D1D33; color: #FCA5A5; }
[data-theme="dark"] .alert-info    { background: #1E3A5F33; color: #93C5FD; }

/* ── Login Page ── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo .logo-icon {
    width: 64px;
    height: 64px;
    background: var(--primary);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
    box-shadow: 0 8px 24px rgba(1,71,204,.35);
}

.login-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.login-logo p {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 4px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 28px 24px;
}

/* ── Receipt Gallery Grid ── */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.receipt-thumb {
    aspect-ratio: 3/4;
    background: var(--bg);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: transform 0.15s;
    text-decoration: none;
    display: block;
    border: 1.5px solid var(--border);
}

.receipt-thumb:active { transform: scale(0.96); }

.receipt-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.receipt-thumb .pdf-thumb {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 500;
}

.receipt-thumb .pdf-thumb svg {
    width: 28px;
    height: 28px;
    color: var(--danger);
}

.receipt-thumb .receipt-id-badge {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,.6));
    color: #fff;
    font-size: 0.6rem;
    font-weight: 600;
    padding: 12px 5px 5px;
    text-align: center;
}

/* ── Upload / Camera Page ── */
.upload-card {
    padding: 0;
    overflow: hidden;
    margin-bottom: 0;
}

.upload-alt-link {
    text-align: center;
    margin: 10px 0 20px;
    font-size: 0.83rem;
}

.upload-alt-link label {
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    padding: 4px 0;
    border-bottom: 1px dashed var(--border);
    transition: color 0.15s;
}

.upload-alt-link label:hover { color: var(--primary); }

.upload-zone {
    border: none;
    border-radius: 0;
    padding: 36px 20px;
    text-align: center;
    cursor: pointer;
    background: var(--bg);
    transition: border-color 0.15s, background 0.15s;
    position: relative;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}

/* file inputs inside upload-zone are hidden and triggered by JS */

.upload-zone .upload-icon {
    width: 52px;
    height: 52px;
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
    color: var(--primary);
}

.upload-zone p { color: var(--text-muted); font-size: 0.88rem; }
.upload-zone strong { color: var(--text); font-size: 0.95rem; display: block; margin-bottom: 6px; }

.preview-box {
    display: none;
    position: relative;
}

.preview-box img {
    width: 100%;
    height: 280px;
    object-fit: contain;
    background: var(--bg);
    display: block;
}

#preview-pdf {
    height: 200px;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 24px;
    text-align: center;
}

.preview-change-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: rgba(0,0,0,.55);
    color: #fff;
    border: none;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ── Receipt Detail Page ── */
.receipt-image-wrap {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.receipt-image-wrap img {
    width: 100%;
    max-height: 360px;
    object-fit: contain;
    background: #f8f8f8;
}

.receipt-pdf-wrap {
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px 20px;
    text-align: center;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    color: var(--text-muted);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}
.detail-row:last-child { border-bottom: none; }
.detail-row .label { font-size: 0.82rem; color: var(--text-muted); font-weight: 500; flex-shrink: 0; }
.detail-row .value { font-size: 0.9rem; font-weight: 500; text-align: right; word-break: break-word; }

.action-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 4px;
}

/* ── Profile Page ── */
.profile-avatar {
    width: 72px;
    height: 72px;
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.profile-header h2 { font-size: 1.1rem; font-weight: 600; }
.profile-header .role-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-top: 4px;
}
.role-badge.admin { background: #FEF3C7; color: #92400E; }
.role-badge.user  { background: var(--primary-light); color: var(--primary); }

[data-theme="dark"] .role-badge.admin { background: #44330a; color: #FCD34D; }

/* ── Admin Tables ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.data-table th {
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }

/* Admin tabs */
.admin-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg);
    padding: 4px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.admin-tab {
    flex: 1;
    min-width: 90px;
    padding: 8px 12px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
    text-align: center;
}
.admin-tab.active {
    background: var(--card);
    color: var(--primary);
    font-weight: 600;
    box-shadow: var(--shadow);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Misc ── */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 12px; opacity: 0.4; }
.empty-state p { font-size: 0.9rem; }
.empty-state strong { display: block; font-size: 1rem; color: var(--text); margin-bottom: 6px; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary);
}

/* ── Spinner ── */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Gallery top bar ── */
.gallery-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 8px;
}
.gallery-topbar h2 { font-size: 1rem; font-weight: 600; }
.gallery-topbar .count { font-size: 0.82rem; color: var(--text-muted); }

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal-box {
    background: var(--card);
    border-radius: 18px 18px 0 0;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
.modal-overlay.open .modal-box { transform: translateY(0); }

.modal-title { font-size: 1rem; font-weight: 600; margin-bottom: 16px; }

/* ── Responsive adjustments ── */
@media (max-width: 360px) {
    .gallery-grid { grid-template-columns: repeat(3, 1fr); gap: 5px; }
    .content { padding: 14px; }
}

/* ── Transition fade ── */
.fade-in {
    animation: fadeIn 0.25s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Upload toast popup ── */
.upload-toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: #22c55e;
    color: #fff;
    padding: 10px 24px;
    border-radius: 24px;
    font-size: .88rem;
    font-weight: 600;
    opacity: 0;
    transition: opacity .25s, transform .25s;
    z-index: 300;
    white-space: nowrap;
    pointer-events: none;
}
.upload-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.upload-toast.upload-toast-error { background: #ef4444; }