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

:root {
    --bg:         #0f1117;
    --surface:    #1a1f2e;
    --surface2:   #222840;
    --border:     #2a3347;
    --text:       #e2e8f0;
    --muted:      #64748b;
    --primary:    #3b82f6;
    --primary-bg: #0d1f3c;
    --green:      #22c55e;
    --green-bg:   #052010;
    --orange:     #f59e0b;
    --orange-bg:  #1f1500;
    --red:        #ef4444;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top nav ── */
.topnav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 58px;
    position: sticky;
    top: 0;
    z-index: 200;
}

.topnav .brand {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 9px;
    letter-spacing: .02em;
}

.topnav nav { display: flex; gap: 4px; }

.topnav nav a {
    padding: 7px 14px;
    border-radius: 7px;
    font-size: .875rem;
    font-weight: 500;
    color: var(--muted);
    transition: background .15s, color .15s;
}

.topnav nav a:hover,
.topnav nav a.active {
    background: var(--surface2);
    color: var(--text);
    text-decoration: none;
}

.cam-pill {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: .78rem;
    color: var(--muted);
    background: var(--surface2);
    padding: 5px 12px;
    border-radius: 20px;
}

.cam-pill .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--muted);
    transition: background .4s;
    flex-shrink: 0;
}

.cam-pill.online  .dot { background: var(--green); box-shadow: 0 0 5px var(--green); }
.cam-pill.offline .dot { background: var(--red);   box-shadow: 0 0 5px var(--red); }

/* ── Page wrapper ── */
.page { max-width: 1280px; margin: 0 auto; padding: 28px 20px; }

/* ── Stats row ── */
.stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 28px; }
@media(max-width:900px){ .stats { grid-template-columns: repeat(2,1fr); } }
@media(max-width:500px){ .stats { grid-template-columns: 1fr; } }

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 20px;
}
.stat .lbl {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--muted);
    margin-bottom: 8px;
}
.stat .val { font-size: 2.1rem; font-weight: 700; line-height: 1; }
.stat.s-total   .val { color: var(--primary); }
.stat.s-loyalty .val { color: var(--green); }
.stat.s-walkin  .val { color: var(--orange); }
.stat.s-pts     .val { color: #a78bfa; }

/* ── Section heading ── */
.sec-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.sec-head h2 {
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--muted);
}
.live-dot {
    display: inline-block;
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--green);
    margin-right: 6px;
    animation: blink 1.2s ease-in-out infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.2} }

/* ── Detection feed ── */
#feed { display: flex; flex-direction: column; gap: 11px; }

.det-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: 10px;
    display: grid;
    grid-template-columns: 118px 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 13px 18px;
    animation: slideIn .3s ease;
}

.det-card.loyalty { border-left-color: var(--green); }
.det-card.walkin  { border-left-color: var(--muted); }

@keyframes slideIn { from{transform:translateY(-10px);opacity:0} to{transform:none;opacity:1} }

.plate-thumb {
    width: 118px; height: 52px;
    background: var(--surface2);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.plate-thumb img { width:100%; height:100%; object-fit:cover; }
.plate-thumb .no-img { font-size:.68rem; color:var(--muted); text-align:center; }

.card-body { min-width: 0; }

.plate-num {
    font-size: 1.45rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    letter-spacing: .1em;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-sub {
    font-size: .8rem;
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.cust-name {
    color: var(--green);
    font-weight: 600;
    font-size: .82rem;
}

.enroll-link {
    color: var(--primary);
    font-size: .78rem;
    border: 1px solid var(--primary);
    border-radius: 4px;
    padding: 1px 7px;
}
.enroll-link:hover { background: var(--primary-bg); text-decoration: none; }

.card-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

.badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: .73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    white-space: nowrap;
}
.badge.loyalty { background: var(--green-bg); color: var(--green); border: 1px solid var(--green); }
.badge.walkin  { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.badge.pts     { background: #1a1040; color: #a78bfa; border: 1px solid #7c3aed; }

/* ── Empty state ── */
.empty {
    text-align: center;
    padding: 70px 20px;
    color: var(--muted);
}
.empty p { font-size: .9rem; margin-top: 14px; }

/* ── Error bar ── */
#err-bar {
    background: #2a0a0a;
    border-bottom: 1px solid var(--red);
    color: #f87171;
    text-align: center;
    padding: 9px;
    font-size: .82rem;
    display: none;
}

/* ── Toast ── */
#toasts {
    position: fixed;
    bottom: 22px; right: 22px;
    display: flex; flex-direction: column; gap: 9px;
    z-index: 999;
}
.toast {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 12px 16px;
    font-size: .82rem;
    max-width: 300px;
    animation: toastIn .3s ease;
    display: flex; align-items: center; gap: 10px;
}
.toast.loyalty { border-left: 4px solid var(--green); }
.toast.walkin  { border-left: 4px solid var(--muted); }
@keyframes toastIn { from{transform:translateX(40px);opacity:0} to{transform:none;opacity:1} }

/* ── Customers page ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.page-header h1 { font-size: 1.3rem; font-weight: 700; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: opacity .15s;
    text-decoration: none;
}
.btn:hover { opacity: .85; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger  { background: var(--red); color: #fff; }
.btn-ghost   { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-sm      { padding: 5px 11px; font-size: .78rem; }

/* Form card */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px 28px;
    margin-bottom: 28px;
}
.form-card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 18px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}
@media(max-width:800px){ .form-grid { grid-template-columns: 1fr; } }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.form-group input,
.form-group textarea {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    padding: 9px 12px;
    font-size: .9rem;
    outline: none;
    transition: border-color .15s;
    font-family: inherit;
}
.form-group input:focus,
.form-group textarea:focus { border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 70px; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; }

.msg { padding: 11px 16px; border-radius: 8px; font-size: .875rem; margin-bottom: 16px; }
.msg.success { background: var(--green-bg); border: 1px solid var(--green); color: var(--green); }
.msg.error   { background: #2a0a0a; border: 1px solid var(--red); color: #f87171; }

/* Table */
.tbl-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th {
    background: var(--surface2);
    padding: 12px 16px;
    text-align: left;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    font-weight: 700;
}
tbody tr { border-top: 1px solid var(--border); transition: background .12s; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 13px 16px; font-size: .875rem; }
tbody td .plate-cell {
    font-family: 'Courier New', monospace;
    font-weight: 700;
    font-size: .95rem;
    letter-spacing: .08em;
}
.pts-badge {
    display: inline-block;
    background: #1a1040;
    color: #a78bfa;
    border: 1px solid #7c3aed;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: .75rem;
    font-weight: 700;
}
.td-actions { display: flex; gap: 6px; }

/* Customer detail */
.detail-grid { display: grid; grid-template-columns: 300px 1fr; gap: 20px; }
@media(max-width:800px){ .detail-grid { grid-template-columns: 1fr; } }

.profile-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
}
.profile-card .avatar {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--primary-bg);
    border: 2px solid var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.6rem;
    margin-bottom: 14px;
}
.profile-card .cname { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; }
.profile-card .cplate {
    font-family: 'Courier New', monospace;
    font-size: .95rem; font-weight: 700;
    color: var(--primary);
    letter-spacing: .1em;
    margin-bottom: 14px;
}
.profile-card .info-row {
    display: flex; justify-content: space-between;
    padding: 9px 0;
    border-top: 1px solid var(--border);
    font-size: .85rem;
}
.profile-card .info-row .key { color: var(--muted); }
.points-big {
    font-size: 2.8rem;
    font-weight: 800;
    color: #a78bfa;
    line-height: 1;
    margin: 10px 0 6px;
}
.points-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.history-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}
.history-card h3 {
    padding: 16px 20px;
    font-size: .85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
}

.tx-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 20px;
    border-bottom: 1px solid var(--border);
    font-size: .875rem;
}
.tx-row:last-child { border-bottom: none; }
.tx-pts { font-weight: 700; }
.tx-pts.pos { color: var(--green); }
.tx-pts.neg { color: var(--red); }

/* Redeem form */
.redeem-form {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.redeem-form input[type=number] {
    width: 80px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    padding: 7px 10px;
    font-size: .875rem;
    outline: none;
}

/* ── Responsive cards ── */
@media(max-width:580px){
    .det-card { grid-template-columns: 1fr auto; }
    .plate-thumb { display: none; }
}
