:root {
    --bg: #0d1017;
    --surface: #151923;
    --surface-2: #1c2230;
    --border: rgba(255, 255, 255, 0.08);
    --text: #eef1f7;
    --muted: #8e98ad;
    --accent: #5865f2;
    --accent-hover: #4752c4;
    --green: #23a55a;
    --amber: #f0b232;
    --red: #f23f43;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--red); font-size: 0.9rem; margin: 8px 0; }

.login-overlay {
    min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
    background: radial-gradient(circle at top, #1f2747 0%, #0d1017 65%);
}
.login-card {
    width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 18px; padding: 28px; box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.brand-badge {
    width: 56px; height: 56px; border-radius: 14px; background: var(--accent);
    display: flex; align-items: center; justify-content: center; font-size: 1.8rem; margin-bottom: 12px;
}

.admin-layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 260px; background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 6px 10px 18px; border-bottom: 1px solid var(--border); }
.sidebar-brand i { font-size: 1.8rem; color: var(--accent); }
.sidebar-brand small { display: block; color: var(--muted); }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 4px; margin-top: 14px; overflow-y: auto; }
.nav-item {
    border: none; background: transparent; color: var(--muted); text-align: left;
    padding: 10px 12px; border-radius: 10px; cursor: pointer; font-family: inherit;
    font-size: 0.92rem; display: flex; align-items: center; gap: 10px; transition: 0.15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.sidebar-footer { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }

.main-content { flex: 1; padding: 22px 26px; overflow-x: hidden; }
.topbar {
    display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;
    margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.35rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.worker-pill {
    display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
    font-size: 0.85rem; font-weight: 600; border: 1px solid var(--border); background: var(--surface);
}
.worker-pill .dot { width: 9px; height: 9px; border-radius: 50%; }
.worker-pill.online { border-color: rgba(35,165,90,0.4); color: #57f287; }
.worker-pill.online .dot { background: #23a55a; box-shadow: 0 0 8px #23a55a; }
.worker-pill.offline { border-color: rgba(240,178,50,0.4); color: var(--amber); }
.worker-pill.offline .dot { background: var(--amber); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px;
}
.kpi-card span { display: block; color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; }
.kpi-card strong { font-size: 1.35rem; }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
    padding: 18px; margin-bottom: 18px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 1.05rem; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }

.form-group, .stack-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 120px; }
label { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
input, select, textarea {
    width: 100%; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
    padding: 9px 12px; border-radius: 9px; font-family: inherit; font-size: 0.9rem;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }

.btn {
    border: none; border-radius: 9px; padding: 9px 14px; font-family: inherit; font-weight: 600;
    font-size: 0.88rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    text-decoration: none;
}
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn-full { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--green); color: #fff; }
.btn-warning { background: var(--amber); color: #111; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-danger-outline { background: transparent; color: var(--red); border: 1px solid rgba(242,63,67,0.4); }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar select { max-width: 240px; }
.toolbar input { flex: 1; min-width: 200px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }

.badge {
    display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 0.76rem; font-weight: 700;
}
.badge-queued_auto { background: rgba(88,101,242,0.2); color: #94a3ff; }
.badge-queued_manual { background: rgba(240,178,50,0.2); color: var(--amber); }
.badge-processing { background: rgba(59,130,246,0.2); color: #60a5fa; }
.badge-completed { background: rgba(35,165,90,0.2); color: #57f287; }
.badge-failed { background: rgba(242,63,67,0.2); color: #ff7b7e; }
.badge-waiting_payment { background: rgba(142,152,173,0.2); color: var(--muted); }

.orders-stack { display: flex; flex-direction: column; gap: 12px; }
.order-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.order-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.order-item-row {
    display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 10px 0; border-bottom: 1px dashed rgba(255,255,255,0.06);
}
.order-item-row:last-child { border-bottom: none; }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center;
    justify-content: center; padding: 20px; z-index: 100;
}
.modal-card {
    width: 100%; max-width: 460px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 22px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.toast {
    position: fixed; bottom: 20px; right: 20px; background: var(--accent); color: #fff;
    padding: 12px 18px; border-radius: 10px; font-weight: 600; z-index: 200;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
@media (max-width: 860px) {
    .admin-layout { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; }
}
