/* Mobile-first UI */

:root {
    --bottom-nav-h: 4.25rem;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --header-h: 3.25rem;
}

html {
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

body {
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
}

@media (min-width: 1024px) {
    body { padding-bottom: 0; }
}

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.75rem 1.25rem; border-radius: 0.875rem;
    font-size: 1rem; font-weight: 500; min-height: 3rem;
    transition: background 0.15s, transform 0.1s; cursor: pointer; border: 1px solid transparent;
    -webkit-user-select: none; user-select: none; text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-success { background: #059669; color: #fff; border-color: #059669; }
.btn-danger  { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-outline { background: #fff; color: #334155; border-color: #e2e8f0; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.625rem 1rem; font-size: 0.875rem; min-height: 2.75rem; }

@media (min-width: 1024px) {
    .btn { padding: 0.5rem 1rem; font-size: 0.875rem; min-height: auto; }
    .btn-sm { padding: 0.375rem 0.75rem; font-size: 0.75rem; min-height: auto; }
}

.form-label { display: block; font-size: 0.9375rem; font-weight: 600; color: #334155; margin-bottom: 0.5rem; }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 0.875rem 1rem; border-radius: 0.875rem;
    border: 1px solid #e2e8f0; font-size: 16px; background: #fff; min-height: 3rem;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.form-textarea { resize: vertical; min-height: 100px; }

.card { background: #fff; border-radius: 1rem; border: 1px solid #e2e8f0; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.card-header { padding: 1rem 1.125rem; border-bottom: 1px solid #f1f5f9; font-weight: 600; }
.card-body { padding: 1rem 1.125rem; }

.badge { display: inline-flex; align-items: center; padding: 0.25rem 0.625rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 600; }
.badge-success { background: #d1fae5; color: #047857; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }
.badge-info    { background: #dbeafe; color: #1d4ed8; }

.stat-card { background: #fff; border-radius: 1rem; border: 1px solid #e2e8f0; padding: 1rem; }
.stat-label { font-size: 0.8125rem; color: #64748b; line-height: 1.3; }
.stat-value { font-size: 1.375rem; font-weight: 700; color: #0f172a; margin-top: 0.25rem; }
.stat-icon  { font-size: 1.75rem; }

.alert { padding: 0.875rem 1rem; border-radius: 0.875rem; font-size: 0.9375rem; font-weight: 500; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.nav-item, .nav-active {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.875rem 1rem; border-radius: 0.875rem; font-size: 0.9375rem; text-decoration: none;
}
.nav-item { color: #475569; }
.nav-active { font-weight: 600; background: #eff6ff; color: #1d4ed8; }

.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: #fff; border-top: 1px solid #e2e8f0;
    padding-bottom: var(--safe-bottom); box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
}
.bottom-nav-inner { display: flex; height: var(--bottom-nav-h); max-width: 32rem; margin: 0 auto; }
.bottom-tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 0.125rem; font-size: 0.625rem; font-weight: 500; color: #94a3b8; text-decoration: none;
}
.bottom-tab-icon { font-size: 1.375rem; }
.bottom-tab.active { color: #2563eb; font-weight: 600; }

.fab {
    position: fixed; z-index: 45;
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 0.75rem); right: 1rem;
    width: 3.75rem; height: 3.75rem; border-radius: 50%;
    background: #2563eb; color: #fff; font-size: 1.75rem;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 20px rgba(37,99,235,0.45); text-decoration: none;
}
@media (min-width: 1024px) { .bottom-nav, .fab { display: none !important; } }

.list-card {
    display: block; background: #fff; border-radius: 1rem; border: 1px solid #e2e8f0;
    padding: 1rem; margin-bottom: 0.75rem; text-decoration: none; color: inherit;
}
.list-card:active { background: #f8fafc; }
.list-card-top { display: flex; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.5rem; }
.list-card-title { font-weight: 600; font-size: 1rem; flex: 1; }
.list-card-amount { font-weight: 700; color: #2563eb; white-space: nowrap; }
.list-card-meta { display: flex; flex-wrap: wrap; gap: 0.375rem; font-size: 0.8125rem; color: #64748b; align-items: center; }
.list-card-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }

.desktop-only { display: none !important; }
.mobile-only  { display: block !important; }
@media (min-width: 1024px) {
    .desktop-only { display: block !important; }
    .mobile-only  { display: none !important; }
}

.filter-toggle {
    width: 100%; display: flex; align-items: center; justify-content: space-between;
    padding: 0.875rem 1rem; background: #fff; border: 1px solid #e2e8f0;
    border-radius: 0.875rem; font-weight: 600; margin-bottom: 0.75rem; min-height: 3rem; cursor: pointer;
}
.filter-panel { display: none; }
.filter-panel.open { display: block; }
.filter-bar {
    background: #fff; border-radius: 1rem; border: 1px solid #e2e8f0;
    padding: 1rem; margin-bottom: 1rem; display: grid; grid-template-columns: 1fr; gap: 0.875rem;
}
@media (min-width: 1024px) {
    .filter-toggle { display: none; }
    .filter-panel { display: block !important; }
    .filter-bar { grid-template-columns: repeat(4, 1fr); }
}

.search-bar { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.search-bar .form-input { flex: 1; margin: 0; }

.form-actions-sticky {
    position: fixed; bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
    left: 0; right: 0; z-index: 40; background: #fff; border-top: 1px solid #e2e8f0;
    padding: 0.75rem 1rem; display: flex; gap: 0.5rem; box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
}
.form-actions-sticky .btn { flex: 1; }
.form-page { padding-bottom: 5.5rem; }
@media (min-width: 1024px) {
    .form-actions-sticky { display: none; }
    .form-page { padding-bottom: 0; }
}

.profile-sheet { position: fixed; inset: 0; z-index: 60; display: none; }
.profile-sheet.open { display: block; }
.profile-sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.profile-sheet-content {
    position: absolute; bottom: 0; left: 0; right: 0; background: #fff;
    border-radius: 1.25rem 1.25rem 0 0; padding: 1.25rem 1.25rem calc(1.25rem + var(--safe-bottom));
}

.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-content { position: relative; background: #fff; width: 100%; border-radius: 1.25rem 1.25rem 0 0; max-height: 92vh; overflow: hidden; }
@media (min-width: 768px) {
    .modal { align-items: center; padding: 1rem; }
    .modal-content { border-radius: 1rem; max-width: 56rem; }
}

.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; font-size: 0.875rem; border-collapse: collapse; }
table.data-table th { padding: 0.75rem 1rem; text-align: left; font-size: 0.75rem; color: #64748b; background: #f8fafc; }
table.data-table td { padding: 0.75rem 1rem; border-top: 1px solid #f1f5f9; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: #94a3b8; }
.file-chip { display: inline-flex; padding: 0.5rem 0.75rem; background: #f1f5f9; border-radius: 0.625rem; font-size: 0.8125rem; }

.app-main { flex: 1; padding: 0.875rem 1rem; }
@media (min-width: 1024px) { .app-main { padding: 1.5rem; } }

.app-header {
    position: sticky; top: 0; z-index: 30; background: rgba(255,255,255,0.95);
    border-bottom: 1px solid #e2e8f0; height: var(--header-h); padding: 0 1rem;
    display: flex; align-items: center; gap: 0.75rem;
}
.app-header-title { font-size: 1.0625rem; font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar-btn {
    width: 2.5rem; height: 2.5rem; border-radius: 50%; background: #dbeafe; color: #1d4ed8;
    font-weight: 700; border: none; cursor: pointer; flex-shrink: 0;
}
@media (min-width: 1024px) {
    .app-shell { margin-left: 16rem; }
    .mobile-header-actions { display: none; }
    #sidebar { display: flex !important; }
}

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.625rem; margin-bottom: 1rem; }
@media (min-width: 1280px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

.login-page { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 1.25rem; padding-bottom: calc(1.25rem + var(--safe-bottom)); }
body.login-page { padding-bottom: 0; }
.login-test-accounts { display: none; }
@media (min-width: 640px) { .login-test-accounts { display: block; } }

.approval-card { margin-bottom: 0.875rem; }
.page-count { font-size: 0.875rem; color: #64748b; margin-bottom: 0.75rem; }

.app-logo { display: block; border-radius: 0.875rem; box-shadow: 0 4px 12px rgba(37,99,235,0.25); }
.app-logo-sm { width: 2.5rem; height: 2.5rem; }
.app-logo-lg { width: 5rem; height: 5rem; margin: 0 auto; border-radius: 1.25rem; box-shadow: 0 8px 24px rgba(0,0,0,0.2); }

/* หน้าอัปโหลดบิล (หน้าแรก) */
.hidden-input { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }

.upload-zone {
    background: #fff; border: 2px dashed #cbd5e1; border-radius: 1.25rem;
    padding: 2rem 1.25rem; text-align: center;
}
.upload-zone.has-photos { padding: 1.25rem; border-style: solid; border-color: #bfdbfe; background: #f8fbff; }
.upload-zone-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.upload-zone-title { font-size: 1.125rem; font-weight: 700; color: #0f172a; margin-bottom: 0.25rem; }
.upload-zone-hint { font-size: 0.875rem; color: #64748b; margin-bottom: 1.25rem; }
.upload-zone-btns { display: flex; flex-direction: column; gap: 0.625rem; max-width: 16rem; margin: 0 auto; }
@media (min-width: 480px) { .upload-zone-btns { flex-direction: row; max-width: none; justify-content: center; } }
.upload-zone-btns label { cursor: pointer; }

.photo-preview-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem;
    margin-top: 0.875rem;
}
.photo-preview-grid.hidden { display: none; }
.photo-preview-item {
    position: relative; aspect-ratio: 1; border-radius: 0.75rem; overflow: hidden;
    background: #f1f5f9; border: 1px solid #e2e8f0;
}
.photo-preview-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview-remove {
    position: absolute; top: 0.25rem; right: 0.25rem;
    width: 1.75rem; height: 1.75rem; border-radius: 50%;
    background: rgba(0,0,0,0.65); color: #fff; border: none;
    font-size: 1.125rem; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.photo-count { font-size: 0.875rem; color: #2563eb; font-weight: 600; margin-top: 0.5rem; text-align: center; }
.photo-count.hidden { display: none; }

.upload-more-fields summary {
    cursor: pointer; font-weight: 600; color: #475569; padding: 0.5rem 0;
    list-style: none;
}
.upload-more-fields summary::-webkit-details-marker { display: none; }
.upload-more-fields summary::before { content: '▸ '; }
.upload-more-fields[open] summary::before { content: '▾ '; }

.upload-page .form-actions-sticky .btn-primary:disabled,
.upload-page #submit-btn-desktop:disabled { opacity: 0.45; cursor: not-allowed; }

.upload-summary {
    display: flex; align-items: center; background: #fff;
    border: 1px solid #e2e8f0; border-radius: 1rem;
    padding: 0.875rem 1rem; margin-bottom: 0.875rem;
}
.upload-summary-item { flex: 1; text-align: center; }
.upload-summary-label { display: block; font-size: 0.75rem; color: #64748b; margin-bottom: 0.125rem; }
.upload-summary-value { font-size: 1.125rem; font-weight: 700; color: #0f172a; }
.upload-summary-divider { width: 1px; height: 2.5rem; background: #e2e8f0; }

.amount-input-wrap { position: relative; display: flex; align-items: center; }
.amount-input-prefix {
    position: absolute; left: 1rem; font-size: 1.25rem; font-weight: 700; color: #64748b; pointer-events: none;
}
.amount-input { padding-left: 2.5rem !important; font-size: 1.375rem !important; font-weight: 600; min-height: 3.25rem !important; }
