/* ============================================================
   ActiveBook Redeem System — shared stylesheet
   ============================================================ */
:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --success: #16a34a;
    --success-hover: #15803d;
    --success-soft: #dcfce7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --info-soft: #e0f2fe;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, .10);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body.ab-body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    min-height: 100vh;
}

/* ---------- Top bar ---------- */
.ab-topbar {
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 60%, #3730a3 100%);
    color: #fff;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
    flex-wrap: wrap;
    gap: 8px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, .25);
    position: sticky;
    top: 0;
    z-index: 50;
}

.ab-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: .2px;
    color: #fff;
    text-decoration: none;
    padding: 10px 0;
}

.ab-brand .ab-logo {
    background: rgba(255, 255, 255, .14);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.ab-brand small {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: #c7d2fe;
    letter-spacing: .3px;
}

.ab-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.ab-nav a {
    color: #e0e7ff;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    padding: 8px 14px;
    border-radius: 8px;
    transition: background .15s, color .15s;
}

.ab-nav a:hover { background: rgba(255, 255, 255, .12); color: #fff; }

.ab-nav a.active { background: rgba(255, 255, 255, .18); color: #fff; }

.ab-nav .ab-user {
    color: #c7d2fe;
    font-size: 13px;
    padding: 8px 10px;
    max-width: 260px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Layout ---------- */
.ab-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 20px 60px;
}

.ab-page-title {
    margin: 0 0 4px;
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -.3px;
}

.ab-page-sub {
    margin: 0 0 24px;
    color: var(--muted);
    font-size: 14px;
}

.ab-grid {
    display: grid;
    gap: 20px;
}

.ab-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ab-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ab-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 980px) {
    .ab-grid.cols-3, .ab-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .ab-grid.cols-2, .ab-grid.cols-3, .ab-grid.cols-4 { grid-template-columns: 1fr; }
    .ab-container { padding: 18px 12px 40px; }
}

/* ---------- Cards ---------- */
.ab-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 20px;
}

.ab-card > h3, .ab-card > h2 {
    margin: 0 0 14px;
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ab-card .ab-card-sub {
    margin: -8px 0 16px;
    color: var(--muted);
    font-size: 13px;
}

.ab-card.accent-primary { border-top: 3px solid var(--primary); }
.ab-card.accent-warning { border-top: 3px solid var(--warning); }
.ab-card.accent-success { border-top: 3px solid var(--success); }

/* ---------- Stat tiles ---------- */
.ab-stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ab-stat .ab-stat-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
}

.ab-stat .ab-stat-value {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -.5px;
}

.ab-stat .ab-stat-value.warn { color: var(--warning); }
.ab-stat .ab-stat-value.ok { color: var(--success); }
.ab-stat .ab-stat-value.bad { color: var(--danger); }

/* ---------- Forms ---------- */
.ab-label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin: 0 0 6px;
    color: #334155;
}

.ab-input, .ab-select {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}

.ab-input:focus, .ab-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

input[type="file"].ab-input { padding: 8px; }

/* ---------- Buttons ---------- */
.ab-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, transform .05s;
    line-height: 1.2;
}

.ab-btn:hover { background: var(--primary-hover); }
.ab-btn:active { transform: translateY(1px); }

.ab-btn.success { background: var(--success); }
.ab-btn.success:hover { background: var(--success-hover); }

.ab-btn.danger { background: var(--danger); }
.ab-btn.danger:hover { background: #b91c1c; }

.ab-btn.secondary {
    background: #fff;
    color: #334155;
    border: 1px solid #cbd5e1;
}
.ab-btn.secondary:hover { background: #f8fafc; }

.ab-btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 6px; }
.ab-btn.block { width: 100%; }

/* ---------- Tables ---------- */
.ab-table-wrap { overflow-x: auto; }

.ab-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.ab-table th {
    text-align: left;
    padding: 10px 12px;
    background: #f8fafc;
    color: #475569;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.ab-table td {
    padding: 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.ab-table tbody tr:hover { background: #f8fafc; }

/* ---------- Badges ---------- */
.ab-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .4px;
    text-transform: uppercase;
    white-space: nowrap;
}

.ab-badge.pending { background: var(--warning-soft); color: #92400e; }
.ab-badge.done { background: var(--success-soft); color: #166534; }
.ab-badge.wait { background: #e2e8f0; color: #475569; }
.ab-badge.used { background: var(--danger-soft); color: #991b1b; }
.ab-badge.avail { background: var(--success-soft); color: #166534; }

.ab-stock-ok { color: var(--success); font-weight: 700; }
.ab-stock-low { color: var(--warning); font-weight: 700; }
.ab-stock-out { color: var(--danger); font-weight: 700; }

/* ---------- Instruction / help boxes ---------- */
.ab-help {
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-left: 4px solid var(--primary);
    border-radius: 8px;
    padding: 14px 18px;
    margin: 0 0 20px;
    font-size: 13.5px;
    color: #3730a3;
    line-height: 1.6;
}

.ab-help h4 {
    margin: 0 0 6px;
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #312e81;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ab-help p { margin: 0 0 8px; }
.ab-help p:last-child, .ab-help ol:last-child, .ab-help ul:last-child { margin-bottom: 0; }

.ab-help ol, .ab-help ul {
    margin: 6px 0 8px;
    padding-left: 22px;
}

.ab-help li { margin-bottom: 4px; }
.ab-help li:last-child { margin-bottom: 0; }

.ab-help strong { color: #312e81; }

.ab-help.compact {
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* ---------- Alerts ---------- */
.ab-alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 18px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
}

.ab-alert.success { background: var(--success-soft); color: #166534; border-color: #bbf7d0; }
.ab-alert.error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.ab-alert.info { background: var(--info-soft); color: #075985; border-color: #bae6fd; }

/* ---------- Login ---------- */
.ab-login-wrap {
    max-width: 420px;
    margin: 8vh auto 0;
    padding: 0 16px;
}

.ab-login-brand {
    text-align: center;
    margin-bottom: 22px;
}

.ab-login-brand .ab-logo-big {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    box-shadow: var(--shadow-lg);
}

.ab-login-brand h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.ab-login-brand p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.ab-login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: 28px;
}

/* ---------- Total box (order form) ---------- */
.ab-total-box {
    background: var(--primary-soft);
    border: 1px solid #c7d2fe;
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 15px;
}

.ab-total-box strong { font-size: 20px; color: var(--primary); }

/* ---------- Redeem card (print) ---------- */
.ab-redeem-card {
    border: 2px dashed #94a3b8;
    border-radius: 12px;
    padding: 40px;
    max-width: 620px;
    margin: 30px auto;
    text-align: center;
    background: #fff;
    page-break-inside: avoid;
}

.ab-redeem-title { font-size: 22px; font-weight: 800; color: #1e1b4b; margin-bottom: 6px; }
.ab-redeem-book { font-size: 17px; color: #334155; margin-bottom: 18px; }

.ab-redeem-code {
    background: #f1f5f9;
    font-family: "Consolas", "Menlo", monospace;
    font-size: 26px;
    padding: 16px;
    margin: 18px 0;
    letter-spacing: 3px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    word-break: break-all;
}

.ab-redeem-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--muted);
}

.ab-redeem-link { font-size: 16px; margin: 6px 0 18px; word-break: break-all; }
.ab-redeem-link a { color: var(--primary); }

.ab-redeem-instr {
    font-size: 13px;
    color: #475569;
    line-height: 1.7;
    text-align: left;
    display: inline-block;
}

.ab-redeem-foot { margin-top: 26px; font-size: 12px; color: #94a3b8; }

/* ---------- Invoice ---------- */
.ab-invoice {
    background: #fff;
    max-width: 800px;
    margin: 0 auto;
    padding: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: #334155;
}

.ab-invoice-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    border-bottom: 2px solid var(--border);
    padding-bottom: 20px;
    margin-bottom: 28px;
}

.ab-invoice-title { font-size: 30px; font-weight: 800; color: #1e1b4b; text-transform: uppercase; letter-spacing: 1px; }

.ab-invoice-meta { text-align: right; font-size: 14px; }

.ab-invoice-total { text-align: right; font-size: 18px; font-weight: 800; color: var(--text); }

.ab-print-bar {
    max-width: 800px;
    margin: 0 auto 18px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ---------- DataTables integration ---------- */
.dataTables_wrapper { font-size: 13px; }
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 5px 8px;
    margin-left: 6px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: var(--primary) !important;
    color: #fff !important;
    border: 1px solid var(--primary) !important;
    border-radius: 6px;
}

/* ---------- Utilities ---------- */
.ab-flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.ab-muted { color: var(--muted); }
.ab-mt-0 { margin-top: 0; }
.ab-mono { font-family: "Consolas", "Menlo", monospace; font-size: 12px; }

/* ---------- Print ---------- */
@media print {
    body.ab-body { background: #fff; }
    .ab-topbar, .ab-print-bar, .ab-no-print, .ab-help { display: none !important; }
    .ab-container { padding: 0; max-width: none; }
    .ab-redeem-card { border: 2px solid #000; margin: 0 auto; }
    .ab-invoice { border: none; box-shadow: none; padding: 0; border-radius: 0; }
}
