:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --success: #059669;
    --success-soft: #ecfdf5;
    --success-border: #a7f3d0;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --danger-border: #fecaca;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

a:hover {
    text-decoration: underline;
}

/* Top Navigation */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 20px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
    text-decoration: none;
}

.brand:hover {
    text-decoration: none;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.9rem;
    letter-spacing: -0.02em;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link {
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover,
.nav-link.active {
    background: var(--primary-soft);
    color: var(--primary);
    text-decoration: none;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Container & Layout */
.container {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 28px 28px 56px;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.page-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.page-subtitle {
    margin: 4px 0 0;
    font-size: 0.92rem;
    color: var(--text-muted);
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}

.card-body {
    padding: 22px;
}

/* Stat Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.stat-value {
    margin-top: 6px;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
}

.stat-value.success { color: var(--success); }
.stat-value.danger { color: var(--danger); }
.stat-value.primary { color: var(--primary); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    line-height: 1.25;
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--primary);
    color: #fff;
}

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

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--surface-muted);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: #047857;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-ghost-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: var(--danger-border);
}

.btn-ghost-danger:hover {
    background: #fee2e2;
}

.btn-ghost-success {
    background: var(--success-soft);
    color: var(--success);
    border-color: var(--success-border);
}

.btn-ghost-success:hover {
    background: #d1fae5;
}

.btn-sm {
    padding: 6px 11px;
    font-size: 0.8rem;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.badge::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.badge-active {
    background: var(--success-soft);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.badge-inactive {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

.badge-serial {
    background: var(--primary-soft);
    color: var(--primary);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.82rem;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 700;
}

.badge-serial::before {
    display: none;
}

.badge-warning {
    background: var(--warning-soft);
    color: var(--warning);
    border: 1px solid #fde68a;
}

/* Alerts */
.alert {
    padding: 13px 16px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    font-weight: 500;
}

.alert-success {
    background: var(--success-soft);
    color: #065f46;
    border: 1px solid var(--success-border);
}

.alert-danger {
    background: var(--danger-soft);
    color: #991b1b;
    border: 1px solid var(--danger-border);
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full {
    grid-column: 1 / -1;
}

.form-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.form-control {
    width: 100%;
    padding: 10px 13px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.92rem;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}

.form-control[readonly] {
    background: var(--surface-muted);
    color: var(--primary);
    font-weight: 700;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

textarea.form-control {
    min-height: 96px;
    resize: vertical;
}

.form-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.form-error {
    font-size: 0.8rem;
    color: var(--danger);
    font-weight: 500;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.toggle-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.form-actions {
    margin-top: 22px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

/* Filter bar */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-muted);
}

.filter-bar .form-control {
    max-width: 280px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

th {
    text-align: left;
    padding: 12px 16px;
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: #fafbff;
}

.actions-cell {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.address-truncate {
    max-width: 240px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Show / QR Detail Layout */
.detail-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 24px;
    align-items: start;
}

.qr-preview-box {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.qr-svg-wrap {
    width: 240px;
    height: 240px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-svg-wrap svg {
    width: 100%;
    height: 100%;
    display: block;
}

.detail-list {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 14px 16px;
    margin: 0;
}

.detail-list dt {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-muted);
}

.detail-list dd {
    margin: 0;
    font-size: 0.94rem;
    color: var(--text);
    word-break: break-word;
}

.url-copy-box {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    width: 100%;
}

.url-copy-box input {
    font-size: 0.8rem;
    padding: 7px 10px;
}

/* Auth Page */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #eef2ff 0%, #f1f5f9 60%, #e0e7ff 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 32px;
}

/* Public Verify Page */
.public-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: linear-gradient(180deg, #eef2ff 0%, #f8fafc 55%, #f1f5f9 100%);
}

.public-card {
    width: 100%;
    max-width: 520px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.public-banner {
    padding: 24px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.public-banner.active {
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
    color: #fff;
}

.public-banner.inactive {
    background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
    color: #fff;
}

.public-field {
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.public-field:last-child {
    border-bottom: none;
}

.public-field-label {
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.public-field-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

/* Pagination */
.pagination-wrap {
    padding: 16px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.pagination-links {
    display: flex;
    gap: 6px;
}

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 820px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .detail-list {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .nav-user span {
        display: none;
    }
}

/* Print QR Label Styles */
@media print {
    body {
        background: #fff;
    }

    .topbar,
    .no-print {
        display: none !important;
    }

    .container {
        padding: 0;
        max-width: 100%;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .card {
        border: none;
        box-shadow: none;
    }
}

/* Bulk QR Label Grid */
.qr-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 18px;
}

.qr-label-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    box-shadow: var(--shadow-sm);
    break-inside: avoid;
    page-break-inside: avoid;
}

.qr-label-svg {
    width: 170px;
    height: 170px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-label-svg svg {
    width: 100%;
    height: 100%;
    display: block;
}

@media print {
    .qr-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }

    .qr-label-card {
        box-shadow: none;
        border: 1px dashed #94a3b8;
        padding: 10px;
    }

    .qr-label-svg {
        width: 135px;
        height: 135px;
    }
}

/* Admin Sidebar Layout */
.admin-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 252px;
    flex-shrink: 0;
    background: #0f172a;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.sidebar-brand {
    height: 64px;
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-close {
    display: none;
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-section {
    padding: 0 10px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: 9px;
    color: #cbd5e1;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.sidebar-footer {
    padding: 14px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 6px;
}

.sidebar-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.25);
    color: #c7d2fe;
    font-weight: 700;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-user-name {
    font-size: 0.86rem;
    font-weight: 600;
    color: #f8fafc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-email {
    font-size: 0.74rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-logout-btn {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.04);
    color: #e2e8f0;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.sidebar-logout-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fecaca;
}

.admin-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.mobile-topbar {
    display: none;
    height: 58px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 35;
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: inline-block;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .mobile-topbar {
        display: flex;
    }
}

@media print {
    .sidebar,
    .mobile-topbar,
    .sidebar-overlay {
        display: none !important;
    }

    .admin-shell {
        display: block;
    }
}
