*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f0f2f5;
    --white: #ffffff;
    --border: #d0d5dd;
    --text: #1a1a2e;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --partial: #0ea5e9;
    --radius: 8px;
    --shadow: 0 1px 4px rgba(0,0,0,.1);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 16px; }

/* --- Layout --- */
.navbar { background: var(--primary); color: #fff; padding: .75rem 1.5rem; display: flex; align-items: center; justify-content: space-between; }
.navbar .brand { font-weight: 700; font-size: 1.1rem; }
.navbar a { color: rgba(255,255,255,.85); text-decoration: none; font-size: .9rem; margin-left: 1.25rem; }
.navbar a:hover { color: #fff; }

.container { max-width: 900px; margin: 1.5rem auto; padding: 0 1rem; }

/* --- Login --- */
.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 80vh; }
.login-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2.5rem; width: 100%; max-width: 380px; }
.login-card h1 { font-size: 1.5rem; margin-bottom: 1.5rem; text-align: center; }

/* --- Forms --- */
label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .35rem; }
input[type=text], input[type=password], select {
    width: 100%; padding: .6rem .8rem; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 1rem; outline: none;
    transition: border-color .15s;
}
input:focus, select:focus { border-color: var(--primary); }
.form-group { margin-bottom: 1.1rem; }

.btn { display: inline-block; padding: .65rem 1.4rem; border: none; border-radius: var(--radius);
       font-size: 1rem; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-success  { background: var(--success);  color: #fff; }
.btn-success:hover  { background: #15803d; }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-danger:hover   { background: #b91c1c; }
.btn-warning  { background: var(--warning);  color: #fff; }
.btn-warning:hover  { background: #b45309; }
.btn-secondary{ background: #e5e7eb; color: var(--text); }
.btn-secondary:hover{ background: #d1d5db; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-warning { background: #fef9c3; color: #854d0e; border: 1px solid #fde68a; }

/* --- Operator page --- */
.order-header { background: var(--white); border-radius: var(--radius); padding: 1.2rem 1.5rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.order-header h2 { font-size: 1.3rem; }
.order-header .customer { margin-top: .5rem; font-size: .9rem; color: var(--muted); line-height: 1.6; }

.barcode-section { background: var(--white); border-radius: var(--radius); padding: 1.2rem 1.5rem; box-shadow: var(--shadow); margin-bottom: 1rem; display: flex; gap: .75rem; align-items: center; }
.barcode-section input { flex: 1; font-size: 1.2rem; padding: .6rem 1rem; }
.barcode-section .btn { white-space: nowrap; }

#scan-feedback { min-height: 2rem; font-weight: 600; font-size: .95rem; }
.feedback-ok      { color: var(--success); }
.feedback-dup     { color: var(--warning); }
.feedback-wrong   { color: var(--danger); }
.feedback-missing { color: var(--danger); }

/* --- Product list --- */
.items-list { list-style: none; }
.item-row {
    background: var(--white);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.2rem;
    margin-bottom: .6rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    box-shadow: var(--shadow);
    transition: border-color .2s, background .2s;
}
.item-row .item-icon { font-size: 1.4rem; flex-shrink: 0; min-width: 1.6rem; text-align: center; }
.item-row .item-info { flex: 1; }
.item-row .item-title { font-weight: 600; font-size: 1rem; }
.item-row .item-meta  { font-size: .8rem; color: var(--muted); margin-top: .2rem; line-height: 1.6; }
.item-row .item-qty   { font-size: 1rem; font-weight: 700; white-space: nowrap; flex-shrink: 0; }
.item-row .item-actions { flex-shrink: 0; display: flex; flex-direction: column; gap: .4rem; }

/* Status colours */
.item-pending     { border-color: var(--border); }
.item-partial     { border-color: var(--partial); background: #f0f9ff; }
.item-completed   { border-color: var(--success); background: #f0fdf4; }
.item-substituted { border-color: var(--warning); background: #fffbeb; }
.item-missing     { border-color: var(--danger);  background: #fff1f2; }

.item-completed .item-title { text-decoration: line-through; color: var(--success); }

.close-order-wrap { text-align: center; margin: 1.5rem 0; }
#btn-close-order  { padding: 1rem 3rem; font-size: 1.1rem; display: none; }

.no-orders-msg { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.no-orders-msg h2 { font-size: 1.5rem; margin-bottom: .5rem; }
.spinner { display: inline-block; width: 2rem; height: 2rem; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; margin-bottom: 1rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Modal --- */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 100; align-items: center; justify-content: center; }
.modal-overlay.active { display: flex; }
.modal { background: var(--white); border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 480px; box-shadow: 0 8px 32px rgba(0,0,0,.2); }
.modal h3 { font-size: 1.2rem; margin-bottom: 1rem; }
.modal .sub-info { font-size: .9rem; background: #f9fafb; border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; color: var(--muted); }
.modal .sub-buttons { display: flex; flex-direction: column; gap: .5rem; }
.modal .sub-buttons .btn { text-align: left; font-weight: 500; }
.modal .btn-cancel { margin-top: .5rem; }

/* --- Reports --- */
.report-controls { background: var(--white); border-radius: var(--radius); padding: 1.2rem 1.5rem; box-shadow: var(--shadow); margin-bottom: 1rem; display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.report-controls .form-group { margin-bottom: 0; }
.report-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--white); border-radius: var(--radius); padding: 1.2rem; text-align: center; box-shadow: var(--shadow); }
.stat-card .stat-num { font-size: 2.5rem; font-weight: 700; }
.stat-card .stat-label { font-size: .85rem; color: var(--muted); margin-top: .2rem; }
.stat-card.ok   .stat-num { color: var(--success); }
.stat-card.anom .stat-num { color: var(--danger); }

.anomaly-card { background: var(--white); border-radius: var(--radius); padding: 1.2rem 1.5rem; box-shadow: var(--shadow); margin-bottom: 1rem; border-left: 4px solid var(--danger); }
.anomaly-card h4 { font-size: 1rem; margin-bottom: .5rem; }
.anomaly-card ul { padding-left: 1.2rem; font-size: .9rem; color: var(--muted); line-height: 1.8; }

@media (max-width: 600px) {
    .report-summary { grid-template-columns: 1fr; }
    .barcode-section { flex-direction: column; }
    .item-row { flex-wrap: wrap; }
}
