/* Flora Checks — Greenhouse Monitor Aesthetic
   Industrial precision meets botanical warmth
   v1.0.0 */

:root {
    --green-900: #1b5e20;
    --green-800: #2e7d32;
    --green-700: #388e3c;
    --green-600: #43a047;
    --green-500: #4caf50;
    --green-400: #66bb6a;
    --green-100: #e8f5e9;
    --green-50: #f1f8e9;
    --blue-700: #1565c0;
    --blue-100: #e3f2fd;
    --red-600: #e53935;
    --red-100: #ffebee;
    --amber-600: #f9a825;
    --amber-100: #fff8e1;
    --gray-900: #1a1a1a;
    --gray-800: #2d2d2d;
    --gray-700: #424242;
    --gray-600: #616161;
    --gray-500: #9e9e9e;
    --gray-400: #bdbdbd;
    --gray-300: #e0e0e0;
    --gray-200: #eeeeee;
    --gray-100: #f5f5f5;
    --gray-50: #fafafa;
    --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(0,0,0,.06), 0 1px 3px rgba(0,0,0,.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.05);
    --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, #screen-setup {
    background: var(--green-900);
    background-image:
        radial-gradient(ellipse at 30% 20%, rgba(46,125,50,.4) 0%, transparent 60%),
        radial-gradient(ellipse at 70% 80%, rgba(21,101,192,.15) 0%, transparent 50%);
    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(--green-400);
    opacity: .9;
}
.login-icon.setup { color: var(--amber-600); }

.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,.5);
    letter-spacing: .08em;
    text-transform: uppercase;
    font-family: var(--font-mono);
}

.login-form {
    background: rgba(255,255,255,.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,.1);
    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,.08);
    border: 1.5px solid rgba(255,255,255,.15);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .2s, background .2s;
}
.input-group input::placeholder { color: rgba(255,255,255,.35); }
.input-group input:focus {
    border-color: var(--green-400);
    background: rgba(255,255,255,.12);
}

.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(--green-600);
    color: var(--white);
}
.btn-primary:active { background: var(--green-700); }

.btn-outline {
    background: transparent;
    color: var(--green-800);
    border: 1.5px solid var(--green-800);
}

.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(--green-800);
    color: var(--white);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

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

/* Header */
.app-header {
    height: var(--header-height);
    padding: var(--safe-top) 16px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--green-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(--green-400);
}

.header-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--green-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,.1);
    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,.7);
}

/* ============================================
   MAIN SCREEN
   ============================================ */

/* Scan Button */
.scan-button {
    width: 100%;
    padding: 28px 24px;
    background: linear-gradient(135deg, var(--green-800), var(--green-700));
    border: none;
    border-radius: var(--radius-lg);
    color: var(--white);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow-md), 0 0 0 1px rgba(255,255,255,.05) inset;
    -webkit-tap-highlight-color: transparent;
    transition: transform .15s, box-shadow .15s;
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
}
.scan-button::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,.08) 100%);
    pointer-events: none;
}
.scan-button:active {
    transform: scale(.98);
    box-shadow: var(--shadow-sm);
}

.scan-button-icon {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    opacity: .9;
}
.scan-button-icon svg { width: 100%; height: 100%; }

.scan-button-text {
    font-family: var(--font-ui);
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -.01em;
}

/* 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(--green-50);
    border-color: var(--green-100);
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 24px;
    font-weight: 600;
    color: var(--green-800);
    line-height: 1.2;
    margin-bottom: 4px;
}
.stat-card.accent .stat-value { color: var(--green-900); }

.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);
}

.section-badge {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--blue-700);
    background: var(--blue-100);
    padding: 3px 8px;
    border-radius: 4px;
    letter-spacing: .05em;
}

/* Receipt 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;
    position: relative;
    overflow: hidden;
}
.receipt-card:active { background: var(--gray-50); }

.receipt-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.receipt-status.success { background: var(--green-500); }
.receipt-status.pending { background: var(--amber-600); }
.receipt-status.error { background: var(--red-600); }
.receipt-status.manual { background: var(--gray-400); }

.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-user-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    color: var(--primary);
    background: rgba(46, 125, 50, 0.1);
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 6px;
    vertical-align: middle;
}

.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;
}

/* Swipe delete */
.receipt-card .swipe-delete {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 80px;
    background: var(--red-600);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-size: 13px;
    font-weight: 600;
    transform: translateX(80px);
    transition: transform .2s ease;
}
.receipt-card.swiped .swipe-delete { transform: translateX(0); }
.receipt-card .swipe-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    background: var(--white);
    transition: transform .2s ease;
    position: relative;
    z-index: 1;
    padding: 14px 16px;
    margin: -14px -16px;
}
.receipt-card.swiped .swipe-inner { transform: translateX(-80px); }

/* 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(--green-800);
}

/* 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(--green-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;
}
/* Hide html5-qrcode default UI */
#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-result {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 24px 20px calc(var(--safe-bottom) + 24px);
    box-shadow: var(--shadow-scanner);
    animation: sheetUp .4s cubic-bezier(.16,1,.3,1) both;
    max-height: 60vh;
    overflow-y: auto;
}
@keyframes sheetUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.scanner-result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 20px;
}

.result-success {
    text-align: center;
}

.result-amount {
    font-family: var(--font-mono);
    font-size: 36px;
    font-weight: 600;
    color: var(--green-800);
    margin: 12px 0 4px;
    letter-spacing: -.02em;
}

.result-seller {
    font-size: 14px;
    color: var(--gray-600);
    margin-bottom: 4px;
}

.result-date {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--gray-400);
}

.result-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    margin-top: 8px;
}
.result-status.success { background: var(--green-100); color: var(--green-800); }
.result-status.pending { background: var(--amber-100); color: #f57f17; }
.result-status.error { background: var(--red-100); color: var(--red-600); }
.result-status.manual { background: var(--gray-200); color: var(--gray-600); }
.result-status.duplicate { background: var(--amber-100); color: #e65100; }

/* ============================================
   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(--green-500); }

.filter-sep {
    color: var(--gray-400);
    font-size: 14px;
    flex-shrink: 0;
}

/* ============================================
   REPORTS
   ============================================ */
.report-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.report-card {
    background: var(--white);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 14px;
}

.report-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
}
.report-icon.posted { background: var(--green-100); color: var(--green-800); }
.report-icon.pending { background: var(--amber-100); color: #f57f17; }
.report-icon.failed { background: var(--red-100); color: var(--red-600); }

.report-info { flex: 1; }

.report-date {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-800);
}

.report-details {
    font-size: 12px;
    color: var(--gray-500);
    font-family: var(--font-mono);
    margin-top: 2px;
}

.report-amount {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-900);
}

/* ============================================
   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(0,0,0,.4);
    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);
}

.modal-handle {
    width: 40px;
    height: 4px;
    background: var(--gray-300);
    border-radius: 2px;
    margin: 12px auto 0;
}

.modal-content {
    padding: 20px 20px 24px;
}

/* Modal receipt 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(--green-800);
    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-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 8px 0;
    border-bottom: 1px solid var(--gray-100);
    gap: 12px;
}
.detail-item:last-child { border-bottom: none; }

.detail-item-name {
    font-size: 13px;
    color: var(--gray-700);
    flex: 1;
}

.detail-item-qty {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--gray-400);
    white-space: nowrap;
}

.detail-item-sum {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-800);
    white-space: nowrap;
}

.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); }

.detail-note {
    margin-top: 12px;
}
.detail-note textarea {
    width: 100%;
    height: 60px;
    padding: 10px 12px;
    font-family: var(--font-ui);
    font-size: 14px;
    color: var(--gray-800);
    background: var(--gray-50);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    resize: none;
    outline: none;
}
.detail-note textarea:focus { border-color: var(--green-500); }

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

/* ============================================
   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(--green-800); }
.nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--green-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); }
}
