/* BAPU Order Hub — Admin UI */

:root {
    --slate-900: #0f172a;
    --slate-800: #1e293b;
    --slate-700: #334155;
    --slate-500: #64748b;
    --slate-400: #94a3b8;
    --slate-200: #e2e8f0;
    --slate-100: #f1f5f9;
    --slate-50: #f8fafc;
    --blue-600: #2563eb;
    --blue-500: #3b82f6;
    --green-600: #16a34a;
    --green-50: #f0fdf4;
    --red-600: #dc2626;
    --red-50: #fef2f2;
    --amber-600: #d97706;
    --amber-50: #fffbeb;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
}

* , *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--slate-100);
    color: var(--slate-800);
    font-size: 14.5px;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; }

/* ─── Auth screen ─────────────────────────────────── */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, var(--slate-900), var(--slate-700));
}
.admin-login-card {
    width: 100%; max-width: 420px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
    overflow: hidden;
}
.admin-login-header { background: var(--slate-800); color: #fff; text-align: center; padding: 2rem 1.5rem; }
.admin-login-header h2 { font-size: 1.4rem; font-weight: 700; margin-bottom: 0.25rem; }
.admin-login-header p { font-size: 0.85rem; opacity: 0.65; }
.admin-login-body { padding: 2rem 1.5rem; }
.admin-login-footer { text-align: center; padding: 1rem 1.5rem; border-top: 1px solid var(--slate-100); font-size: 0.8rem; color: var(--slate-400); }

/* ─── Layout ───────────────────────────────────────── */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar {
    width: 240px; flex-shrink: 0;
    background: var(--slate-800); color: #fff;
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    transition: transform 0.2s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: 0.6rem; padding: 1.35rem 1.25rem; font-weight: 700; font-size: 1.05rem; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-brand i { color: var(--blue-500); }
.sidebar-nav { padding: 0.75rem 0.6rem; display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar-link { display: flex; align-items: center; gap: 0.7rem; padding: 0.65rem 0.85rem; border-radius: 8px; color: rgba(255,255,255,0.72); font-size: 0.92rem; font-weight: 500; }
.sidebar-link i { width: 18px; text-align: center; }
.sidebar-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-link.active { background: var(--blue-600); color: #fff; }

.admin-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.admin-topbar {
    display: flex; align-items: center; gap: 1rem;
    padding: 0.9rem 1.5rem; background: #fff; border-bottom: 1px solid var(--slate-200);
    position: sticky; top: 0; z-index: 10;
}
.sidebar-toggle { display: none; background: none; border: none; font-size: 1.1rem; color: var(--slate-700); cursor: pointer; }
.topbar-title { font-size: 1.15rem; font-weight: 700; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.topbar-user { font-size: 0.88rem; color: var(--slate-500); display: flex; align-items: center; gap: 0.4rem; }
.inline-form { display: inline; }

.admin-content { padding: 1.5rem; flex: 1; }

/* ─── Alerts ───────────────────────────────────────── */
.admin-alert { display: flex; align-items: center; gap: 0.6rem; padding: 0.8rem 1.1rem; border-radius: 8px; font-size: 0.9rem; margin-bottom: 1.25rem; }
.admin-alert-error { background: var(--red-50); color: var(--red-600); border: 1px solid #fecaca; }
.admin-alert-success { background: var(--green-50); color: var(--green-600); border: 1px solid #bbf7d0; }
.admin-alert-warning { background: var(--amber-50); color: var(--amber-600); border: 1px solid #fde68a; }

/* ─── Cards / stats ────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem 1.4rem; display: flex; flex-direction: column; gap: 0.35rem; }
.stat-card .stat-label { font-size: 0.8rem; color: var(--slate-500); font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; color: var(--slate-900); }
.stat-card .stat-sub { font-size: 0.78rem; color: var(--slate-400); }
.stat-card.accent-blue .stat-value { color: var(--blue-600); }
.stat-card.accent-green .stat-value { color: var(--green-600); }

.admin-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.4rem; margin-bottom: 1.25rem; }
.admin-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.1rem; flex-wrap: wrap; gap: 0.75rem; }
.admin-card-header h2 { font-size: 1.05rem; font-weight: 700; }

/* ─── Buttons ──────────────────────────────────────── */
.admin-btn { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.55rem 1.1rem; border-radius: 8px; border: 1px solid transparent; font-size: 0.87rem; font-weight: 600; cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.admin-btn-dark { background: var(--slate-800); color: #fff; }
.admin-btn-dark:hover { background: var(--slate-700); }
.admin-btn-primary { background: var(--blue-600); color: #fff; }
.admin-btn-primary:hover { background: var(--blue-500); }
.admin-btn-ghost { background: transparent; color: var(--slate-600); border-color: var(--slate-200); }
.admin-btn-ghost:hover { background: var(--slate-100); }
.admin-btn-danger { background: var(--red-50); color: var(--red-600); border-color: #fecaca; }
.admin-btn-danger:hover { background: #fee2e2; }
.admin-btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
.admin-btn-block { width: 100%; justify-content: center; }
.admin-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Forms ────────────────────────────────────────── */
.admin-form-group { margin-bottom: 1.1rem; }
.admin-form-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--slate-700); margin-bottom: 0.4rem; }
.admin-form-group .hint { font-size: 0.76rem; color: var(--slate-400); margin-top: 0.3rem; }
.admin-input-wrap { display: flex; align-items: center; border: 1px solid #d1d5db; border-radius: 8px; overflow: hidden; transition: border-color 0.15s; background: #fff; }
.admin-input-wrap:focus-within { border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(59,130,246,0.12); }
.admin-input-icon { padding: 0 0.7rem; color: #9ca3af; font-size: 0.85rem; }
.admin-input-wrap input, .admin-input-wrap select { flex: 1; border: none; outline: none; padding: 0.65rem 0.75rem 0.65rem 0; font-size: 0.92rem; background: transparent; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
    width: 100%; padding: 0.6rem 0.75rem; border: 1px solid #d1d5db; border-radius: 8px; font-size: 0.92rem; font-family: inherit; outline: none; transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(59,130,246,0.12); }
textarea { resize: vertical; min-height: 90px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

/* ─── Tables ───────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.admin-table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
table.admin-table th { text-align: left; padding: 0.7rem 0.9rem; background: var(--slate-50); color: var(--slate-500); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--slate-200); white-space: nowrap; }
table.admin-table th.sortable { cursor: pointer; user-select: none; }
table.admin-table th.sortable:hover { color: var(--slate-800); }
table.admin-table th.sortable i { margin-left: 0.3rem; opacity: 0.5; }
table.admin-table td { padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--slate-100); vertical-align: middle; }
table.admin-table tbody tr:hover { background: var(--slate-50); }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ─── Badges ───────────────────────────────────────── */
.badge { display: inline-block; padding: 0.25rem 0.6rem; border-radius: 999px; font-size: 0.74rem; font-weight: 600; text-transform: capitalize; }
/* Order status workflow (config/constants.php ORDER_STATUSES), in pipeline order */
.badge-order-placed { background: #eef2ff; color: #4338ca; }
.badge-processing, .badge-info, .badge-on-hold { background: #eff6ff; color: var(--blue-600); }
.badge-ready-to-dispatch, .badge-pending, .badge-warning { background: var(--amber-50); color: var(--amber-600); }
.badge-dispatched { background: #ecfeff; color: #0e7490; }
.badge-shipped { background: #f0fdfa; color: #0f766e; }
.badge-delivered { background: #f0fdf4; color: #15803d; }
.badge-completed, .badge-success { background: var(--green-50); color: var(--green-600); }
.badge-cancelled, .badge-failed, .badge-danger { background: var(--red-50); color: var(--red-600); }
.badge-muted { background: var(--slate-100); color: var(--slate-500); }

/* ─── Inline status-change control (orders list + detail page) ─────── */
.status-select-wrap { display: inline-flex; align-items: center; gap: 0.4rem; }
.status-select { padding: 0.35rem 0.55rem; border: 1px solid var(--slate-200); border-radius: 6px; font-size: 0.78rem; background: #fff; cursor: pointer; }
.status-select:disabled { opacity: 0.5; cursor: wait; }
.status-save-hint { font-size: 0.72rem; visibility: hidden; white-space: nowrap; }
.status-save-hint.ok { color: var(--green-600); visibility: visible; }
.status-save-hint.err { color: var(--red-600); visibility: visible; }

/* ─── Toolbar / filters ────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.toolbar input, .toolbar select { max-width: 220px; }

/* ─── Pagination ───────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 0.35rem; justify-content: flex-end; margin-top: 1rem; }
.pagination button { min-width: 34px; height: 34px; border: 1px solid var(--slate-200); background: #fff; border-radius: 6px; cursor: pointer; font-size: 0.85rem; }
.pagination button.active { background: var(--slate-800); color: #fff; border-color: var(--slate-800); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Modal ────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.55); display: none; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal-overlay.open { display: flex; }
.modal-box { background: #fff; border-radius: var(--radius); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,0.3); }
.modal-box-wide { max-width: 760px; }
.email-preview-frame { width: 100%; height: 420px; border: 1px solid var(--slate-200); border-radius: 8px; background: #fff; }
.email-preview-loading { font-size: 0.8rem; color: var(--slate-400); margin: 0 0 0.4rem; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--slate-100); }
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.1rem; color: var(--slate-400); cursor: pointer; }
.modal-body { padding: 1.4rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.6rem; padding: 1rem 1.4rem; border-top: 1px solid var(--slate-100); }

/* ─── Misc ─────────────────────────────────────────── */
.muted { color: var(--slate-400); }
code { background: var(--slate-100); color: var(--slate-700); padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.85em; font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; }
pre.code-block { background: var(--slate-900); color: #e2e8f0; border-radius: 8px; padding: 1rem 1.1rem; font-size: 0.78rem; line-height: 1.5; overflow-x: auto; max-height: 400px; font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; }
pre.code-block code { background: none; color: inherit; padding: 0; }
.integrate-tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; border-bottom: 1px solid var(--slate-100); }
.integrate-tab { padding: 0.6rem 1rem; font-size: 0.85rem; font-weight: 600; color: var(--slate-400); border-bottom: 2px solid transparent; cursor: default; }
.integrate-tab.active { color: var(--blue-600); border-bottom-color: var(--blue-600); }
.integrate-step { display: flex; gap: 0.7rem; margin-bottom: 0.9rem; }
.integrate-step .step-num { flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%; background: var(--slate-800); color: #fff; font-size: 0.76rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.integrate-step .step-body { font-size: 0.88rem; color: var(--slate-700); line-height: 1.5; padding-top: 0.15rem; }
.api-key-reveal { background: var(--amber-50); border: 1px solid #fde68a; border-radius: 8px; padding: 0.9rem 1rem; margin: 0.8rem 0; font-size: 0.85rem; }
.copy-row { display: flex; align-items: center; gap: 0.6rem; background: var(--slate-900); color: #e2e8f0; border-radius: 8px; padding: 0.55rem 0.7rem; }
.copy-row-label { flex-shrink: 0; width: 110px; color: #94a3b8; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.copy-row-value { flex: 1; min-width: 0; font-size: 0.78rem; font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; word-break: break-all; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.6s linear infinite; }
.spinner-dark { border: 2px solid var(--slate-200); border-top-color: var(--slate-600); }
@keyframes spin { to { transform: rotate(360deg); } }
.email-count { font-size: 0.76rem; color: var(--slate-400); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 720px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-label { font-size: 0.76rem; color: var(--slate-400); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.2rem; }
.detail-value { font-size: 0.92rem; color: var(--slate-800); margin-bottom: 0.9rem; white-space: pre-line; }
pre.raw-payload { background: var(--slate-50); border: 1px solid var(--slate-200); border-radius: 8px; padding: 1rem; font-size: 0.78rem; overflow-x: auto; max-height: 320px; }

@media (max-width: 900px) {
    .admin-sidebar { position: fixed; z-index: 50; transform: translateX(-100%); }
    .admin-sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: inline-block; }
}
