/* ── Reset & Base ────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #000; --bg-grouped: #1C1C1E; --bg-elevated: #2C2C2E;
    --text: #fff; --text2: #EBEBF599; --text3: #8E8E93;
    --tint: #007AFF; --green: #34C759; --red: #FF3B30; --orange: #FF9500;
    --sep: rgba(84,84,88,0.35); --sep-strong: rgba(84,84,88,0.65);
    --radius: 10px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
    background: var(--bg); color: var(--text);
    min-height: 100%; overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

#app { max-width: 428px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(20px + var(--safe-bottom)); }

/* ── Navigation Bar ─────────────────────────── */
.nav {
    position: sticky; top: 0; z-index: 100;
    display: flex; align-items: center; justify-content: space-between;
    height: calc(44px + var(--safe-top)); padding-top: var(--safe-top);
    padding-left: 16px; padding-right: 16px;
    background: rgba(0,0,0,0.85); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 0.5px solid var(--sep-strong);
}
.nav-left, .nav-right { min-width: 70px; display: flex; align-items: center; }
.nav-right { justify-content: flex-end; }
.nav-title { font-size: 17px; font-weight: 600; text-align: center; flex: 1; }
.nav-btn {
    background: none; border: none; color: var(--tint); font-size: 17px;
    padding: 8px 4px; cursor: pointer; font-family: inherit;
}
.nav-btn:active { opacity: 0.5; }
.nav-btn svg { width: 22px; height: 22px; fill: var(--tint); vertical-align: middle; }

/* ── Sections (iOS grouped style) ───────────── */
.section { margin: 20px 16px; }
.section-header {
    font-size: 13px; color: var(--text3); text-transform: uppercase;
    letter-spacing: -0.08px; padding: 0 16px 6px;
}
.section-content {
    background: var(--bg-grouped); border-radius: var(--radius); overflow: hidden;
}

/* ── Rows ────────────────────────────────────── */
.row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 11px 16px; min-height: 44px;
    border-bottom: 0.5px solid var(--sep); gap: 12px;
}
.row:last-child { border-bottom: none; }
.row-tap { cursor: pointer; }
.row-tap:active { background: var(--bg-elevated); }
.row-label { font-size: 17px; color: var(--text); flex-shrink: 0; }
.row-value { font-size: 17px; color: var(--text2); text-align: right; word-break: break-word; }
.row-chevron::after { content: '›'; color: var(--text3); margin-left: 6px; font-size: 20px; font-weight: 300; }

/* ── Stock List Row ──────────────────────────── */
.stock-row { padding: 12px 16px; border-bottom: 0.5px solid var(--sep); cursor: pointer; }
.stock-row:last-child { border-bottom: none; }
.stock-row:active { background: var(--bg-elevated); }
.stock-row-top { display: flex; justify-content: space-between; align-items: center; }
.stock-row-name { font-size: 17px; font-weight: 500; }
.stock-row-count { font-size: 15px; color: var(--text2); font-variant-numeric: tabular-nums; }
.stock-row-sub { font-size: 13px; color: var(--text3); margin-top: 2px; }

/* ── Movement Row ────────────────────────────── */
.movement-row { padding: 10px 16px; border-bottom: 0.5px solid var(--sep); }
.movement-row:last-child { border-bottom: none; }
.movement-top { display: flex; align-items: center; gap: 8px; }
.movement-icon { font-size: 20px; }
.movement-qty { font-size: 15px; font-weight: 500; font-variant-numeric: tabular-nums; }
.movement-note { font-size: 13px; color: var(--text3); margin-top: 2px; padding-left: 28px; }
.movement-time { font-size: 12px; color: var(--text3); margin-top: 1px; padding-left: 28px; }

/* ── Delivery Row ────────────────────────────── */
.delivery-row { padding: 12px 16px; border-bottom: 0.5px solid var(--sep); cursor: pointer; }
.delivery-row:last-child { border-bottom: none; }
.delivery-row:active { background: var(--bg-elevated); }
.delivery-row-top { display: flex; justify-content: space-between; }
.delivery-row-num { font-size: 17px; font-weight: 500; }
.delivery-row-date { font-size: 13px; color: var(--text3); }
.delivery-row-sub { font-size: 13px; color: var(--text3); margin-top: 2px; }

/* ── Buttons ─────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: none; border-radius: var(--radius); padding: 12px 20px;
    font-size: 17px; font-weight: 600; font-family: inherit;
    cursor: pointer; transition: opacity 0.15s;
}
.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-primary { background: var(--tint); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-text { background: none; color: var(--tint); padding: 8px 12px; }
.btn-full { width: 100%; }
.btn-row { display: flex; gap: 12px; padding: 12px 16px; }
.btn-row .btn { flex: 1; }

/* ── Forms ────────────────────────────────────── */
.form-group { padding: 0; }
.form-row {
    display: flex; align-items: center; padding: 0 16px; min-height: 44px;
    border-bottom: 0.5px solid var(--sep);
}
.form-row:last-child { border-bottom: none; }
.form-label { font-size: 17px; width: 110px; flex-shrink: 0; }
.form-input {
    flex: 1; background: none; border: none; color: var(--text); font-size: 17px;
    padding: 11px 0; font-family: inherit; text-align: right; outline: none;
}
.form-input::placeholder { color: var(--text3); }
.form-textarea {
    width: 100%; background: none; border: none; color: var(--text);
    font-size: 17px; padding: 11px 16px; font-family: inherit;
    outline: none; resize: none; min-height: 80px;
}
.form-textarea::placeholder { color: var(--text3); }

/* ── Search Bar ──────────────────────────────── */
.search-wrap { padding: 8px 16px; }
.search-bar {
    display: flex; align-items: center; gap: 6px;
    background: var(--bg-elevated); border-radius: 10px; padding: 8px 10px;
}
.search-bar svg { width: 16px; height: 16px; fill: var(--text3); flex-shrink: 0; }
.search-input {
    flex: 1; background: none; border: none; color: var(--text);
    font-size: 17px; font-family: inherit; outline: none;
}
.search-input::placeholder { color: var(--text3); }

/* ── Empty State ─────────────────────────────── */
.empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 60px 40px; text-align: center;
}
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-title { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.empty-sub { font-size: 15px; color: var(--text3); }

/* ── Auth Screen ─────────────────────────────── */
.auth-page {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; min-height: 100vh; padding: 40px 24px;
}
.auth-icon { font-size: 64px; margin-bottom: 16px; }
.auth-title { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.auth-subtitle { font-size: 17px; color: var(--text3); margin-bottom: 32px; }
.auth-form { width: 100%; max-width: 340px; }
.auth-input {
    width: 100%; background: var(--bg-grouped); border: none; border-radius: var(--radius);
    color: var(--text); font-size: 17px; padding: 14px 16px; margin-bottom: 12px;
    font-family: inherit; outline: none;
}
.auth-input:focus { outline: 1px solid var(--tint); }
.auth-input::placeholder { color: var(--text3); }
.auth-error { color: var(--red); font-size: 14px; margin-bottom: 12px; text-align: center; min-height: 20px; }
.auth-link { color: var(--tint); font-size: 15px; margin-top: 20px; cursor: pointer; background: none; border: none; font-family: inherit; }
.pw-wrap {
    position: relative; width: 100%; margin-bottom: 12px;
}
.pw-wrap .auth-input { margin-bottom: 0; padding-right: 48px; }
.pw-toggle {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text3); cursor: pointer; padding: 4px;
}
.pw-toggle:active { opacity: 0.5; }

/* ── Loading ─────────────────────────────────── */
.loading { display: flex; justify-content: center; padding: 40px; }
.spinner {
    width: 24px; height: 24px; border: 2.5px solid var(--sep);
    border-top-color: var(--text); border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Sheet / Modal ───────────────────────────── */
.sheet-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200;
    opacity: 0; transition: opacity 0.2s;
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
    position: fixed; left: 50%; bottom: 0; z-index: 201;
    transform: translateX(-50%) translateY(100%); transition: transform 0.3s ease-out;
    width: 100%; max-width: 428px;
    background: var(--bg-grouped); border-radius: 12px 12px 0 0;
    padding-bottom: var(--safe-bottom);
}
.sheet.show { transform: translateX(-50%) translateY(0); }
.sheet-handle {
    width: 36px; height: 5px; background: var(--text3); border-radius: 3px;
    margin: 8px auto 4px;
}
.sheet-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; border-bottom: 0.5px solid var(--sep);
}
.sheet-title { font-size: 17px; font-weight: 600; }
.sheet-body { padding: 16px; max-height: 60vh; overflow-y: auto; }

/* ── Segmented Control ───────────────────────── */
.segmented {
    display: flex; background: var(--bg-elevated); border-radius: 8px; padding: 2px;
    margin-bottom: 16px;
}
.segmented-btn {
    flex: 1; padding: 8px; font-size: 13px; font-weight: 600; text-align: center;
    background: none; border: none; color: var(--text3); border-radius: 6px;
    cursor: pointer; font-family: inherit; transition: all 0.2s;
}
.segmented-btn.active { background: var(--bg-grouped); color: var(--text); }

/* ── Quantity Control ────────────────────────── */
.qty-control { display: flex; align-items: center; gap: 12px; }
.qty-btn {
    width: 32px; height: 32px; border-radius: 50%; border: none;
    font-size: 20px; font-weight: 500; display: flex; align-items: center;
    justify-content: center; cursor: pointer; color: #fff;
}
.qty-btn:disabled { opacity: 0.3; }
.qty-btn.minus { background: var(--red); }
.qty-btn.plus { background: var(--green); }
.qty-value { font-size: 17px; font-variant-numeric: tabular-nums; min-width: 24px; text-align: center; }

/* ── Delivery Step Bar ───────────────────────── */
.steps {
    display: flex; gap: 4px; padding: 12px 16px 8px;
}
.step-dot {
    flex: 1; height: 3px; border-radius: 2px; background: var(--bg-elevated);
    transition: background 0.3s;
}
.step-dot.active { background: var(--tint); }
.step-dot.done { background: var(--green); }

/* ── Signature Canvas ────────────────────────── */
.signature-wrap { padding: 16px; text-align: center; }
.signature-label { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.signature-hint { font-size: 15px; color: var(--text3); margin-bottom: 16px; }
.signature-canvas {
    width: 100%; max-width: 380px; height: 200px;
    background: #fff; border-radius: var(--radius); touch-action: none;
    cursor: crosshair;
}

/* ── Image Preview ───────────────────────────── */
.img-preview {
    width: 100%; max-height: 200px; object-fit: cover;
    border-radius: var(--radius); background: var(--bg-elevated);
}
.img-placeholder {
    display: flex; align-items: center; justify-content: center;
    height: 120px; color: var(--text3); font-size: 15px;
    background: var(--bg-elevated); border-radius: var(--radius);
}

/* ── Toast ────────────────────────────────────── */
#toast-container { position: fixed; top: calc(60px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 300; max-width: 380px; width: calc(100% - 32px); }
.toast {
    background: var(--bg-elevated); color: var(--text); padding: 14px 16px;
    border-radius: var(--radius); font-size: 15px; text-align: center;
    animation: toastIn 0.3s ease-out, toastOut 0.3s 2.5s ease-in forwards;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.toast-error { border-left: 3px solid var(--red); }
.toast-success { border-left: 3px solid var(--green); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }

/* ── Utility ─────────────────────────────────── */
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-secondary { color: var(--text3); }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mb-16 { margin-bottom: 16px; }
.px-16 { padding-left: 16px; padding-right: 16px; }
.hidden { display: none !important; }

/* ── Menu ────────────────────────────────────── */
.menu-overlay { position: fixed; inset: 0; z-index: 150; }
.menu {
    position: absolute; top: calc(44px + var(--safe-top) + 4px); left: 12px; z-index: 151;
    background: var(--bg-elevated); border-radius: 12px; min-width: 220px;
    overflow: hidden; box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    animation: menuIn 0.15s ease-out;
}
@keyframes menuIn { from { opacity: 0; transform: scale(0.9); } }
.menu-item {
    display: flex; align-items: center; gap: 10px; padding: 12px 16px;
    font-size: 17px; color: var(--text); cursor: pointer;
    border-bottom: 0.5px solid var(--sep);
}
.menu-item:last-child { border-bottom: none; }
.menu-item:active { background: rgba(255,255,255,0.08); }
.menu-item svg { width: 20px; height: 20px; fill: var(--text3); }
.menu-sep { height: 8px; background: var(--bg); }

/* ── Barcode Scanner ─────────────────────────── */
.scanner-page { position: fixed; inset: 0; z-index: 300; background: #000; }
.scanner-video { width: 100%; height: 100%; object-fit: cover; }
.scanner-overlay {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
}
.scanner-frame {
    width: 250px; height: 250px; border: 2px solid var(--tint); border-radius: 16px;
    position: relative;
}
.scanner-line {
    position: absolute; left: 10%; width: 80%; height: 2px; background: var(--tint);
    top: 50%; animation: scanMove 2s ease-in-out infinite alternate;
}
@keyframes scanMove { from { top: 20%; } to { top: 80%; } }
.scanner-hint { color: var(--text3); font-size: 15px; margin-top: 24px; }
.scanner-result {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: rgba(28,28,30,0.95); backdrop-filter: blur(20px);
    padding: 20px 16px calc(20px + var(--safe-bottom));
    text-align: center;
}
.scanner-code { font-size: 17px; margin-bottom: 12px; word-break: break-all; }
.scanner-close {
    position: absolute; top: calc(16px + var(--safe-top)); left: 16px;
    background: none; border: none; color: #fff; font-size: 17px;
    cursor: pointer; font-family: inherit; z-index: 10;
}

/* html5-qrcode overrides */
#scanner-reader { border: none !important; }
#scanner-reader video { border-radius: 12px; }
#scanner-reader__scan_region { background: transparent !important; }
#scanner-reader__dashboard { display: none !important; }
