/* Flora Bills — Banking Blue Aesthetic
   Distinct from Flora Checks (green)
   v1.1.0 */

:root {
    /* Primary — Deep Blue (banking) */
    --pri-900: #0d253f;
    --pri-800: #0f3460;
    --pri-700: #1a4b8c;
    --pri-600: #1e5faa;
    --pri-500: #2979d6;
    --pri-400: #5c9ce6;
    --pri-300: #90bff0;
    --pri-100: #dce9f7;
    --pri-50: #eef4fb;

    /* Accent — Teal */
    --acc-600: #00897b;
    --acc-100: #e0f2f1;

    /* Semantic */
    --green-700: #2e7d32;
    --green-100: #e8f5e9;
    --red-600: #e53935;
    --red-100: #ffebee;
    --amber-600: #f9a825;
    --amber-100: #fff8e1;
    --blue-700: #1565c0;
    --blue-100: #e3f2fd;

    /* Neutrals */
    --gray-900: #1a1d23;
    --gray-800: #2a2e36;
    --gray-700: #3d4250;
    --gray-600: #5a6070;
    --gray-500: #8c92a0;
    --gray-400: #b0b5c0;
    --gray-300: #d2d5dc;
    --gray-200: #e6e8ec;
    --gray-100: #f2f3f5;
    --gray-50: #f8f9fa;
    --white: #ffffff;

    --font-ui: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;

    --shadow-sm: 0 1px 2px rgba(13,37,63,.06), 0 1px 3px rgba(13,37,63,.1);
    --shadow-md: 0 4px 6px rgba(13,37,63,.07), 0 2px 4px rgba(13,37,63,.06);
    --shadow-lg: 0 10px 25px rgba(13,37,63,.12), 0 4px 10px rgba(13,37,63,.06);
    --shadow-scanner: 0 -20px 60px rgba(0,0,0,.3);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-height: 64px;
    --header-height: 56px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.5;
    color: var(--gray-900);
    background: var(--gray-100);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
    overflow: hidden;
    height: 100dvh;
    width: 100vw;
}

/* Screens */
.screen { display: none; height: 100%; width: 100%; }
.screen.active { display: flex; flex-direction: column; }
.screen-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

/* ============================================
   LOGIN
   ============================================ */
#screen-login {
    background: var(--pri-900);
    background-image:
        radial-gradient(ellipse at 20% 30%, rgba(30,95,170,.5) 0%, transparent 55%),
        radial-gradient(ellipse at 80% 70%, rgba(0,137,123,.15) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 100%, rgba(15,52,96,.6) 0%, transparent 40%);
    justify-content: center;
    align-items: center;
    padding: 24px;
}

.login-wrap {
    width: 100%;
    max-width: 360px;
    animation: loginAppear .6s cubic-bezier(.16,1,.3,1) both;
}
@keyframes loginAppear {
    from { opacity: 0; transform: translateY(24px) scale(.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo { text-align: center; margin-bottom: 40px; }
.login-icon { width: 72px; height: 72px; margin: 0 auto 20px; color: var(--pri-400); opacity: .9; }
.login-logo h1 { font-size: 28px; font-weight: 700; color: var(--white); letter-spacing: -.02em; margin-bottom: 4px; }
.login-subtitle {
    font-size: 14px; font-weight: 500; color: rgba(255,255,255,.45);
    letter-spacing: .08em; text-transform: uppercase; font-family: var(--font-mono);
}

.login-form {
    background: rgba(255,255,255,.06);
    backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: var(--radius-lg); padding: 24px;
}
.input-group { margin-bottom: 16px; }
.input-group input {
    width: 100%; height: 52px; padding: 0 16px;
    font-family: var(--font-ui); font-size: 16px; font-weight: 500;
    color: var(--white); background: rgba(255,255,255,.07);
    border: 1.5px solid rgba(255,255,255,.12);
    border-radius: var(--radius-sm); outline: none;
    transition: border-color .2s, background .2s;
}
.input-group input::placeholder { color: rgba(255,255,255,.3); }
.input-group input:focus { border-color: var(--pri-400); background: rgba(255,255,255,.1); }

.form-error {
    font-size: 13px; color: #ef9a9a; text-align: center;
    margin-top: 12px; min-height: 20px; font-weight: 500;
}

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    height: 52px; padding: 0 28px;
    font-family: var(--font-ui); font-size: 15px; font-weight: 600;
    border: none; border-radius: var(--radius-sm); cursor: pointer;
    transition: all .15s ease; -webkit-tap-highlight-color: transparent;
    user-select: none; gap: 8px;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--pri-600); color: var(--white); }
.btn-primary:active { background: var(--pri-700); }
.btn-outline { background: transparent; color: var(--pri-700); border: 1.5px solid var(--pri-700); }
.btn-danger { background: #d32f2f; color: var(--white); width: 100%; }
.btn-danger:active { background: #b71c1c; }
.btn-full { width: 100%; }
.btn-small {
    height: 40px; padding: 0 16px; font-size: 13px; font-weight: 600;
    background: var(--pri-700); color: var(--white);
    border: none; border-radius: var(--radius-sm); cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .5; pointer-events: none; }

/* ============================================
   APP LAYOUT
   ============================================ */
.app-container { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

.app-header {
    height: var(--header-height); padding: var(--safe-top) 16px 0;
    display: flex; align-items: center; justify-content: space-between;
    background: var(--pri-900); color: var(--white);
    flex-shrink: 0; z-index: 10;
    min-height: calc(var(--header-height) + var(--safe-top));
}
.header-left { display: flex; align-items: center; gap: 8px; }
.header-brand { font-family: var(--font-mono); font-size: 13px; font-weight: 600; letter-spacing: .1em; color: var(--pri-400); }
.header-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--pri-500); }
.header-title { font-size: 17px; font-weight: 600; }
.header-action {
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.08); border: none; border-radius: var(--radius-sm);
    cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.header-action svg { width: 20px; height: 20px; color: rgba(255,255,255,.6); }

/* ============================================
   MAIN SCREEN — ACTION BUTTONS
   ============================================ */
.action-buttons { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }

.scan-button {
    width: 100%; padding: 24px 20px;
    background: linear-gradient(135deg, var(--pri-800), var(--pri-600));
    border: none; border-radius: var(--radius-lg); color: var(--white);
    cursor: pointer; display: flex; align-items: center; gap: 16px;
    box-shadow: var(--shadow-md), 0 0 0 1px rgba(255,255,255,.04) inset;
    -webkit-tap-highlight-color: transparent;
    transition: transform .15s, box-shadow .15s;
    position: relative; overflow: hidden;
}
.scan-button::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,.06) 100%);
    pointer-events: none;
}
.scan-button:active { transform: scale(.98); box-shadow: var(--shadow-sm); }
.scan-button-icon { width: 48px; height: 48px; flex-shrink: 0; opacity: .9; }
.scan-button-icon svg { width: 100%; height: 100%; }
.scan-button-text { font-family: var(--font-ui); font-size: 18px; font-weight: 600; letter-spacing: -.01em; }

.upload-button {
    width: 100%; padding: 18px 20px;
    background: var(--white); border: 2px dashed var(--gray-300);
    border-radius: var(--radius-md); color: var(--gray-700);
    cursor: pointer; display: flex; align-items: center; gap: 16px;
    -webkit-tap-highlight-color: transparent;
    transition: border-color .2s, background .2s;
}
.upload-button:active { background: var(--pri-50); border-color: var(--pri-500); }
.upload-button-icon { width: 40px; height: 40px; flex-shrink: 0; color: var(--pri-600); }
.upload-button-icon svg { width: 100%; height: 100%; }
.upload-button-text { text-align: left; }
.upload-button-text > span { font-size: 15px; font-weight: 600; display: block; }
.upload-hint { font-size: 12px; color: var(--gray-500); display: block; margin-top: 2px; }

.manual-button {
    width: 100%; padding: 14px 20px;
    background: var(--white); border: 1px solid var(--gray-200);
    border-radius: var(--radius-md); color: var(--gray-600);
    cursor: pointer; display: flex; align-items: center; gap: 12px;
    font-family: var(--font-ui); font-size: 14px; font-weight: 500;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s;
}
.manual-button:active { background: var(--gray-50); }
.manual-button svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ============================================
   STATS
   ============================================ */
.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.stat-card {
    background: var(--white); border-radius: var(--radius-md); padding: 16px;
    box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
}
.stat-card.accent { background: var(--pri-50); border-color: var(--pri-100); }
.stat-value {
    font-family: var(--font-mono); font-size: 24px; font-weight: 600;
    color: var(--pri-700); line-height: 1.2; margin-bottom: 4px;
}
.stat-card.accent .stat-value { color: var(--pri-800); }
.stat-label {
    font-size: 12px; font-weight: 500; color: var(--gray-500);
    letter-spacing: .02em; text-transform: uppercase;
}

/* Sections */
.section { margin-bottom: 24px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; padding: 0 4px; }
.section-header h2 { font-size: 16px; font-weight: 600; color: var(--gray-800); }

/* Payment List */
.receipt-list { display: flex; flex-direction: column; gap: 2px; }
.receipt-card {
    background: var(--white); border-radius: var(--radius-sm); padding: 14px 16px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: background .15s;
}
.receipt-card:active { background: var(--gray-50); }

.receipt-status { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.receipt-status.sent { background: var(--acc-600); }
.receipt-status.draft { background: var(--amber-600); }
.receipt-status.error { background: var(--red-600); }
.receipt-status.signed { background: var(--pri-600); }

.receipt-info { flex: 1; min-width: 0; }
.receipt-seller {
    font-size: 14px; font-weight: 500; color: var(--gray-800);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.receipt-meta {
    font-size: 12px; color: var(--gray-500); font-family: var(--font-mono);
    font-weight: 400; margin-top: 2px;
}
.receipt-amount {
    font-family: var(--font-mono); font-size: 15px; font-weight: 600;
    color: var(--gray-900); white-space: nowrap; flex-shrink: 0;
}

/* Empty / Loading */
.empty-state { text-align: center; padding: 40px 20px; color: var(--gray-500); font-size: 14px; }
.loading-spinner {
    width: 32px; height: 32px; border: 3px solid var(--gray-200);
    border-top-color: var(--pri-600); border-radius: 50%;
    animation: spin .8s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   SCANNER
   ============================================ */
#screen-scanner {
    position: fixed; inset: 0; z-index: 100;
    background: var(--gray-900); flex-direction: column;
}
.scanner-container { flex: 1; display: flex; flex-direction: column; position: relative; }
.scanner-header {
    position: absolute; top: 0; left: 0; right: 0; z-index: 10;
    padding: calc(var(--safe-top) + 12px) 16px 12px;
    display: flex; align-items: center; gap: 12px;
    background: linear-gradient(to bottom, rgba(0,0,0,.6), transparent);
    color: var(--white); font-size: 15px; font-weight: 500;
}
.scanner-close {
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.15); backdrop-filter: blur(10px);
    border: none; border-radius: 50%; cursor: pointer;
    -webkit-tap-highlight-color: transparent; flex-shrink: 0;
}
.scanner-close svg { width: 20px; height: 20px; color: var(--white); }

#qr-reader { flex: 1; width: 100%; overflow: hidden; }
#qr-reader video { width: 100% !important; height: 100% !important; object-fit: cover !important; }
#qr-reader__scan_region { display: flex !important; align-items: center; justify-content: center; }
#qr-reader__dashboard { display: none !important; }
#qr-reader__header_message { display: none !important; }
#qr-reader img { display: none !important; }

.scanner-status {
    position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,.7); backdrop-filter: blur(10px);
    color: var(--white); padding: 16px 24px; border-radius: var(--radius-md);
    display: flex; align-items: center; gap: 12px;
    font-size: 14px; font-weight: 500;
}
.scanner-status .loading-spinner {
    width: 20px; height: 20px; margin: 0;
    border-width: 2px; border-top-color: var(--white);
}

/* ============================================
   PAYMENT FORM
   ============================================ */
.form-card {
    background: var(--white); border-radius: var(--radius-md); padding: 20px;
    box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
}
.form-section-title {
    font-size: 11px; font-weight: 600; color: var(--gray-400);
    letter-spacing: .08em; text-transform: uppercase;
    margin: 16px 0 12px; padding-bottom: 8px;
    border-bottom: 1px solid var(--gray-100);
}
.form-section-title:first-child { margin-top: 0; }

.form-group { margin-bottom: 14px; }
.form-group label {
    display: block; font-size: 12px; font-weight: 600; color: var(--gray-600);
    margin-bottom: 6px; letter-spacing: .02em;
}
.form-group input, .form-group textarea {
    width: 100%; padding: 12px 14px;
    font-family: var(--font-ui); font-size: 15px; color: var(--gray-900);
    background: var(--gray-50); border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm); outline: none;
    transition: border-color .2s, background .2s;
}
.form-group input:focus, .form-group textarea:focus {
    border-color: var(--pri-500); background: var(--white);
}
.form-group input::placeholder, .form-group textarea::placeholder { color: var(--gray-400); }
.form-group textarea { resize: none; font-size: 14px; line-height: 1.5; }

.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.form-actions { margin-top: 24px; display: flex; flex-direction: column; gap: 12px; }

/* Filled indicator */
.form-group input.filled { border-color: var(--pri-400); background: var(--pri-50); }

/* Field status (DaData verification) */
.field-status {
    font-size: 11px; line-height: 1.3; margin-top: 3px; min-height: 14px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    transition: color 0.2s;
}
.field-status.loading { color: var(--gray-500); }
.field-status.success { color: var(--acc-600); }
.field-status.warning { color: var(--amber-600); }
.field-status.error { color: var(--red-600); font-weight: 500; }

/* Upload button loading state */
.upload-button.loading {
    opacity: 0.7; pointer-events: none;
}
.upload-button.loading .upload-button-icon svg {
    animation: spin 1s linear infinite;
}

/* ============================================
   FILTER BAR
   ============================================ */
.filter-bar {
    display: flex; align-items: center; gap: 8px; margin-bottom: 16px;
    padding: 12px; background: var(--white); border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200);
}
.filter-date {
    flex: 1; height: 40px; padding: 0 10px;
    font-family: var(--font-mono); font-size: 13px; color: var(--gray-800);
    background: var(--gray-50); border: 1px solid var(--gray-300);
    border-radius: 6px; outline: none; min-width: 0;
}
.filter-date:focus { border-color: var(--pri-500); }
.filter-sep { color: var(--gray-400); font-size: 14px; flex-shrink: 0; }

/* ============================================
   MODAL
   ============================================ */
.modal {
    position: fixed; inset: 0; z-index: 200;
    display: none; align-items: flex-end; justify-content: center;
}
.modal.open { display: flex; }
.modal-overlay {
    position: absolute; inset: 0; background: rgba(13,37,63,.5);
    animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal-sheet {
    position: relative; width: 100%; max-width: 500px; max-height: 85vh;
    background: var(--white); border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    animation: sheetUp .35s cubic-bezier(.16,1,.3,1) both;
    padding-bottom: var(--safe-bottom);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-handle { width: 40px; height: 4px; background: var(--gray-300); border-radius: 2px; margin: 12px auto 0; }
.modal-content { padding: 20px 20px 24px; }

/* Modal detail */
.detail-header { text-align: center; padding-bottom: 16px; border-bottom: 1px solid var(--gray-200); margin-bottom: 16px; }
.detail-amount { font-family: var(--font-mono); font-size: 32px; font-weight: 600; color: var(--pri-700); letter-spacing: -.02em; }
.detail-seller { font-size: 15px; font-weight: 500; color: var(--gray-700); margin-top: 4px; }
.detail-inn { font-family: var(--font-mono); font-size: 12px; color: var(--gray-400); margin-top: 2px; }

.detail-section { margin-bottom: 16px; }
.detail-section-title {
    font-size: 11px; font-weight: 600; color: var(--gray-400);
    letter-spacing: .08em; text-transform: uppercase; margin-bottom: 8px;
}
.detail-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.detail-row-label { color: var(--gray-500); }
.detail-row-value { font-family: var(--font-mono); font-weight: 500; color: var(--gray-800); text-align: right; max-width: 60%; word-break: break-all; }
.detail-row-value.purpose { font-family: var(--font-ui); font-size: 13px; line-height: 1.4; }

.detail-status {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12px; font-weight: 600; padding: 4px 10px;
    border-radius: 20px; margin-top: 8px;
}
.detail-status.sent { background: var(--acc-100); color: var(--acc-600); }
.detail-status.draft { background: var(--amber-100); color: #f57f17; }
.detail-status.error { background: var(--red-100); color: var(--red-600); }
.detail-status.signed { background: var(--pri-100); color: var(--pri-700); }

.detail-actions { margin-top: 16px; display: flex; gap: 12px; }
.detail-actions .btn { flex: 1; height: 44px; font-size: 14px; }

/* Day Group */
.day-group { margin-bottom: 20px; }
.day-header {
    font-family: var(--font-mono); font-size: 12px; font-weight: 600;
    color: var(--gray-500); letter-spacing: .06em; text-transform: uppercase;
    padding: 8px 4px 6px; display: flex; align-items: center; justify-content: space-between;
}
.day-total { font-size: 13px; color: var(--pri-700); }

/* ============================================
   BOTTOM NAV
   ============================================ */
.bottom-nav {
    display: flex; background: var(--white); border-top: 1px solid var(--gray-200);
    padding-bottom: var(--safe-bottom); flex-shrink: 0;
}
.nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; height: var(--nav-height); background: none; border: none;
    font-family: var(--font-ui); font-size: 11px; font-weight: 500;
    color: var(--gray-400); cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: color .15s; position: relative;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--pri-700); }
.nav-item.active::before {
    content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 32px; height: 3px; background: var(--pri-600); border-radius: 0 0 3px 3px;
}

/* ============================================
   TOAST
   ============================================ */
.toast {
    position: fixed; bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
    left: 50%; transform: translateX(-50%) translateY(100px);
    background: var(--gray-800); color: var(--white); padding: 12px 24px;
    border-radius: var(--radius-md); font-size: 14px; font-weight: 500;
    z-index: 300; box-shadow: var(--shadow-lg); opacity: 0;
    transition: transform .3s cubic-bezier(.16,1,.3,1), opacity .3s;
    pointer-events: none; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (min-width: 500px) {
    .screen-content { padding: 20px 24px calc(var(--nav-height) + 24px); }
}
