/* ==========================================================
   PACKING VALIDATOR - baseline stylesheet (Tahap 2)
   ========================================================== */

:root {
    /* Token generik dipetakan ke set brand kraft/ink/paper/tape (dunia
       packing) - satu sumber warna dipakai seluruh app, bukan cuma auth. */
    --bg:        #f5ecdb;
    --card:      #fffdf9;
    --text:      #241f2e;
    --muted:     #8a8272;
    --border:    #e9dfc9;
    --primary:   #241f2e;
    --primary-h: #3a3350;
    --success:   #3f8f5f;
    --danger:    #ff5a3c;
    --warning:   #d98c1f;
    --info:      #2c7a73;
    --radius:    14px;
    --shadow:    0 4px 20px rgba(36, 19, 8, 0.08);

    /* ---- Brand set mentah (dipakai elemen bertekstur/hero khusus) ---- */
    --brand-kraft: #e8a33d;
    --brand-ink:   #241f2e;
    --brand-paper: #fff9f0;
    --brand-tape:  #ff5a3c;
    --brand-mint:  #9fdcd4;
    --brand-muted: #8a8272;
    --font-display: 'Baloo 2', 'Segoe UI', sans-serif;
    --font-body:    'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .greeting, .kpi-value, .scan-panel h2 {
    font-family: var(--font-display);
}

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }
.muted { color: var(--muted); font-size: 0.9rem; }

/* ---------- Topbar ---------- */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
    max-width: 1100px; margin: 0 auto; padding: 14px 24px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar-inner strong { font-family: var(--font-display); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block; padding: 10px 18px;
    border: none; border-radius: var(--radius);
    font-weight: 600; font-size: 0.95rem;
    cursor: pointer; text-decoration: none;
    color: var(--text);
    transition: background 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--brand-paper); }
.btn-primary:hover { background: var(--primary-h); }
.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Alerts ---------- */
.alert {
    padding: 12px 14px; border-radius: var(--radius);
    margin: 12px 0; font-size: 0.95rem;
    border: 1px solid transparent;
}
.alert-error   { background: rgba(255, 90, 60, 0.12); border-color: rgba(255, 90, 60, 0.3); color: #b8320f; }
.alert-info    { background: rgba(44, 122, 115, 0.1); border-color: rgba(44, 122, 115, 0.28); color: #1d5551; }
.alert-success { background: rgba(63, 143, 95, 0.12); border-color: rgba(63, 143, 95, 0.3); color: #2a6640; }

/* ==========================================================
   AUTH (login) - dunia kraft/tape/label, bukan biru kantor generik.
   Struktur: hero band (tekstur + wordmark) -> tape seal -> kartu form.
   ========================================================== */
.auth-body {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--brand-paper);
    font-family: var(--font-body);
    color: var(--brand-ink);
    overflow-x: hidden;
}

/* Wrapper TANPA overflow:hidden - badge sengaja nyembul di luar batas
   hero, jadi gak boleh sewrapper sama elemen yang meng-clip-nya. */
.auth-hero-wrap {
    position: relative;
}
.auth-hero {
    position: relative;
    height: 30dvh;
    min-height: 220px;
    max-height: 320px;
    overflow: hidden;
    background: var(--brand-mint) url('../img/auth-bg.jpg') center 30% / cover no-repeat;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    padding-top: env(safe-area-inset-top);
}
.auth-hero::before {
    /* Nyatuin foto sticker ke palet brand - bukan foto mentah nempel */
    content: '';
    position: absolute; inset: 0;
    background:
        linear-gradient(180deg, rgba(36,31,46,0.15) 0%, rgba(36,31,46,0.55) 100%),
        linear-gradient(0deg, var(--brand-kraft) 0%, rgba(232,163,61,0) 55%);
    mix-blend-mode: multiply;
}
.auth-hero-content {
    position: relative;
    text-align: center;
    color: var(--brand-paper);
}
.auth-wordmark {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: 0.02em;
    margin: 0;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}
.auth-tagline {
    margin: 4px 0 0;
    font-size: 0.85rem;
    font-weight: 500;
    opacity: 0.92;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
}

/* Seal diagonal ala lakban - jahitan putus-putus, motif dunia packing */
.auth-tape {
    position: absolute;
    left: -8%;
    bottom: 34px;
    width: 116%;
    height: 34px;
    background: var(--brand-tape);
    border-top: 2px dashed rgba(255, 249, 240, 0.55);
    border-bottom: 2px dashed rgba(255, 249, 240, 0.55);
    transform: rotate(-2.4deg);
    box-shadow: 0 6px 16px rgba(36, 19, 8, 0.25);
}

.auth-badge {
    position: absolute;
    left: 50%;
    bottom: -34px;
    transform: translateX(-50%);
    width: 68px; height: 68px;
    border-radius: 50%;
    background: var(--brand-paper);
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem;
    box-shadow: 0 8px 20px rgba(36, 19, 8, 0.22);
    z-index: 2;
    animation: badge-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@media (prefers-reduced-motion: reduce) {
    .auth-badge { animation: none; }
}
@keyframes badge-pop {
    from { transform: translateX(-50%) scale(0.4); opacity: 0; }
    to   { transform: translateX(-50%) scale(1); opacity: 1; }
}

.auth-card {
    flex: 1;
    background: var(--brand-paper);
    border-radius: 28px 28px 0 0;
    margin-top: -20px;
    position: relative;
    z-index: 1;
    padding: 44px 24px max(24px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: 0 -10px 30px rgba(36, 19, 8, 0.06);
}
.auth-card h2 {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.6rem;
    margin: 0 0 4px;
    text-align: center;
    color: var(--brand-ink);
}
.auth-card .auth-sub {
    text-align: center;
    color: var(--brand-muted);
    font-size: 0.9rem;
    margin: 0 0 28px;
}

.auth-card form label { display: block; margin-bottom: 22px; }
.auth-card form label span {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--brand-muted);
    margin-bottom: 8px;
}
.auth-card form input {
    width: 100%;
    padding: 8px 2px 10px;
    border: none;
    border-bottom: 2px solid #e6dfd0;
    border-radius: 0;
    background: transparent;
    font-family: var(--font-body);
    font-size: 16px; /* >=16px wajib - cegah auto-zoom iOS Safari saat fokus */
    color: var(--brand-ink);
    transition: border-color 0.15s;
}
.auth-card form input:focus {
    outline: none;
    border-bottom-color: var(--brand-tape);
}

.btn-auth-primary {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 16px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.04em;
    text-align: center;
    cursor: pointer;
    color: var(--brand-paper);
    background: var(--brand-ink);
    border: none;
    border-radius: 999px;
    box-shadow: 0 10px 24px rgba(36, 19, 8, 0.2);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn-auth-primary:active {
    transform: scale(0.98);
    box-shadow: 0 4px 12px rgba(36, 19, 8, 0.18);
}

.auth-alert-error {
    background: rgba(255, 90, 60, 0.12);
    color: #b8320f;
    border: 1px solid rgba(255, 90, 60, 0.3);
    border-radius: var(--radius);
    padding: 12px 14px;
    font-size: 0.88rem;
    margin-bottom: 20px;
    text-align: center;
}

.auth-footer {
    text-align: center;
    margin: 24px 0 4px;
    font-size: 0.75rem;
    color: var(--brand-muted);
}

/* ==========================================================
   TAHAP 3 - Operator Dashboard + Scan + Packing Session
   ========================================================== */

/* Layout helpers */
.container-narrow { max-width: 640px; }
.center { text-align: center; }
.hidden { display: none !important; }
@media (max-width: 480px) {
    .hide-sm { display: none; }
    .container { padding: 16px; }
}

/* Button size variants */
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-lg { padding: 16px 20px; font-size: 1.1rem; }

/* Alert extras */
.alert-warning { background: rgba(217, 140, 31, 0.14); border-color: rgba(217, 140, 31, 0.35); color: #8a5a12; }
.alert-link { color: inherit; text-decoration: underline; font-weight: 600; }

/* ---------- Operator Dashboard ---------- */
.greeting { margin: 8px 0 20px; font-size: 1.5rem; font-weight: 700; }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
}
.kpi {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}
.kpi-label { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.kpi-value { font-size: 2rem; font-weight: 800; color: var(--text); line-height: 1.2; margin-top: 4px; }
.kpi-success .kpi-value { color: var(--success); }
.kpi-warning .kpi-value { color: var(--warning); }

/* Big SCAN CTA button */
.scan-cta {
    display: flex; align-items: center; justify-content: center;
    gap: 14px;
    width: 100%;
    padding: 28px 20px;
    margin: 8px 0 16px;
    background: var(--primary);
    color: var(--brand-paper);
    border: none; border-radius: 999px;
    font-family: var(--font-display);
    font-weight: 700; font-size: 1.25rem;
    text-decoration: none;
    box-shadow: 0 10px 24px rgba(36, 19, 8, 0.22);
    transition: transform 0.05s, box-shadow 0.15s;
}
.scan-cta:hover { box-shadow: 0 12px 30px rgba(36, 19, 8, 0.28); }
.scan-cta:active { transform: translateY(2px) scale(0.99); }
.scan-cta-icon { font-size: 1.8rem; }
.scan-cta-label { letter-spacing: 0.03em; }

/* ---------- Scan Page ---------- */
.scan-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 20px;
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.scan-panel h2 { margin: 0; text-align: center; font-size: 1.25rem; }
.scan-panel p  { margin: 0; }

.scan-illustration {
    font-size: 4rem;
    text-align: center;
    line-height: 1;
    margin: 8px 0;
}
.scan-instruction {
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
}
.scan-reader {
    width: 100%;
    min-height: 300px;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}
.scan-reader video { max-width: 100%; display: block; }

/* Quagga2 scanner: Quagga injects <video> + <canvas> ke .quagga-wrap */
.quagga-wrap,
.zxing-wrap {
    position: relative;
    width: 100%;
    background: #000;
    line-height: 0;
    overflow: hidden;
}
.quagga-wrap video,
.quagga-wrap canvas,
.zxing-video {
    width: 100% !important;
    height: auto !important;
    max-height: 480px;
    object-fit: cover;
    display: block;
}
/* Canvas overlay Quagga (drawingBuffer) menutupi video - transparan */
.quagga-wrap canvas.drawingBuffer {
    position: absolute;
    top: 0; left: 0;
    background: transparent;
}
.zxing-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 90%; height: 70%;
    max-height: 320px;
    border: 3px solid rgba(255, 255, 255, 0.85);
    border-radius: 12px;
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);
}
.zxing-overlay::before,
.zxing-overlay::after {
    content: '';
    position: absolute;
    left: 0; right: 0;
    height: 2px;
    background: var(--brand-tape);
    box-shadow: 0 0 8px var(--brand-tape);
}
.zxing-overlay::before { top: 50%; animation: scanline 1.8s ease-in-out infinite; }
.zxing-overlay::after  { display: none; }
@keyframes scanline {
    0%   { top: 0%; }
    50%  { top: 100%; }
    100% { top: 0%; }
}

.scan-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}
.scan-actions .btn { flex: 1; }

.manual-input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-align: center;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.manual-input:focus {
    outline: none;
    border-color: var(--brand-tape);
    box-shadow: 0 0 0 3px rgba(255, 90, 60, 0.15);
}

.detect-badge {
    display: inline-block;
    align-self: center;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.8rem; font-weight: 700;
    letter-spacing: 0.05em;
}
.detect-badge.success { background: rgba(63, 143, 95, 0.15); color: #2a6640; }
.detect-badge.error   { background: rgba(255, 90, 60, 0.15); color: #b8320f; }

.detect-code {
    text-align: center;
    font-family: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
    font-size: 1.5rem;
    font-weight: 700;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius);
    word-break: break-all;
}

.spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 12px auto;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Packing Session ---------- */
.session-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 20px;
    margin: 16px 0;
}
.session-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}
.session-row:last-child { border-bottom: none; }
.session-label {
    font-size: 0.8rem; font-weight: 600;
    color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em;
}
.session-value { font-weight: 600; text-align: right; }
.session-barcode {
    font-family: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
    font-size: 1rem;
    word-break: break-all;
}

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem; font-weight: 700;
    letter-spacing: 0.05em;
    background: var(--bg);
    color: var(--muted);
}
.status-badge.status-scanned   { background: #dbeafe; color: #1e40af; }
.status-badge.status-recording { background: #fee2e2; color: #991b1b; }
.status-badge.status-uploading { background: #fef3c7; color: #92400e; }
.status-badge.status-completed { background: #dcfce7; color: #14532d; }
.status-badge.status-failed    { background: #fecaca; color: #7f1d1d; }
.status-badge.status-cancelled { background: #e5e7eb; color: #4b5563; }

.btn-record {
    background: var(--danger);
    color: #fff;
    padding: 20px;
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: 0.05em;
}
.btn-record:hover:not(:disabled) { background: #b91c1c; }
.btn-record:disabled { opacity: 0.55; cursor: not-allowed; }

/* ==========================================================
   TAHAP 4 - Rekam & Upload Video
   ========================================================== */
.record-status-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.record-pulse {
    width: 12px; height: 12px;
    border-radius: 50%;
    background: var(--danger);
    animation: pulse-rec 1.2s ease-in-out infinite;
}
@keyframes pulse-rec {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); }
    50%      { opacity: 0.6; box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
}
.record-timer {
    font-family: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
    font-size: 1.5rem;
    font-weight: 700;
}
.record-preview {
    min-height: 260px;
}
.size-estimate {
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

.review-video {
    width: 100%;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    line-height: 0;
}
.review-video video {
    width: 100%;
    max-height: 480px;
    display: block;
}

.upload-progress {
    width: 100%;
    height: 10px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}
.upload-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary);
    transition: width 0.2s ease;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.history-item {
    display: block;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px;
    text-decoration: none;
    color: var(--text);
}
.history-item:hover { box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1); }
.history-item-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.history-barcode {
    font-family: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
    font-weight: 600;
    word-break: break-all;
}
.history-item-meta {
    margin-top: 6px;
    font-size: 0.8rem;
}

/* ==========================================================
   TAHAP 7 - Admin Dashboard
   ========================================================== */
.status-badge.status-active   { background: #dcfce7; color: #14532d; }
.status-badge.status-inactive { background: #e5e7eb; color: #4b5563; }

.search-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.search-bar input[type="text"],
.search-bar select {
    flex: 1;
    min-width: 120px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--card);
    color: var(--text);
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.pagination-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
}
.pagination-link:hover { text-decoration: underline; }

.user-row {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px;
}
.user-row-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.form-inline {
    display: flex;
    align-items: center;
    gap: 6px;
}
.form-inline input[type="password"] {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    width: 140px;
    background: var(--card);
    color: var(--text);
}

/* Form generik (mis. Tambah User Baru) - kotak biasa, bukan underline
   hero-style ala login. Dipakai di luar konteks auth. */
.form-plain label { display: block; margin-bottom: 16px; }
.form-plain label span {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 6px;
}
.form-plain input,
.form-plain select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 16px;
    font-family: var(--font-body);
    background: var(--card);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-plain input:focus,
.form-plain select:focus {
    outline: none;
    border-color: var(--brand-tape);
    box-shadow: 0 0 0 3px rgba(255, 90, 60, 0.12);
}
