/* =============================================================================
   LabelyPrint — admin & customer portal styles
   ============================================================================= */

.admin-body, .auth-body {
    background: #f1f5f9; color: var(--ink);
    font-family: 'Inter', sans-serif;
    margin: 0; min-height: 100vh;
}
.admin-body { display: grid; grid-template-columns: 240px 1fr; }
@media (max-width: 880px) {
    .admin-body { grid-template-columns: 1fr; }
}

/* -------------------------------------------------------------------------- */
/* Sidebar                                                                    */
/* -------------------------------------------------------------------------- */
.admin-sidebar {
    background: #0f172a; color: #cbd5e1;
    padding: 22px 16px;
    display: flex; flex-direction: column; gap: 16px;
    position: sticky; top: 0; height: 100vh;
    border-right: 1px solid #1e293b;
}
@media (max-width: 880px) {
    .admin-sidebar { position: relative; height: auto; }
}

.brand--admin {
    color: #fff; padding: 4px 8px; margin-bottom: 8px;
    display: flex; align-items: center; gap: 10px;
    text-decoration: none;
}
.brand--admin small { color: #a78bfa; font-weight: 500; font-size: 12px; }

.admin-nav { display: flex; flex-direction: column; gap: 2px; flex-grow: 1; }
.admin-nav a {
    color: #94a3b8; padding: 9px 12px; border-radius: 7px;
    font-weight: 500; font-size: 14px; text-decoration: none;
    transition: background .12s, color .12s;
}
.admin-nav a:hover { background: #1e293b; color: #fff; }
.admin-nav a.is-active {
    background: rgba(99,102,241,.18); color: #a5b4fc;
    box-shadow: inset 3px 0 0 #6366f1;
}

.admin-sidebar-footer {
    border-top: 1px solid #1e293b; padding-top: 16px;
    display: flex; flex-direction: column; gap: 10px;
}
.admin-user { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.admin-user-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg,#6366f1,#8b5cf6); color: #fff;
    display: grid; place-items: center; font-weight: 700;
}
.admin-user-name { color: #fff; font-size: 14px; font-weight: 600; }
.admin-user-email { color: #64748b; font-size: 12px; }

.admin-logout {
    background: none; border: 1px solid #1e293b; color: #cbd5e1;
    padding: 8px 12px; border-radius: 7px; font: inherit; cursor: pointer;
    transition: background .12s, color .12s;
}
.admin-logout:hover { background: #1e293b; color: #fff; }

.admin-back { color: #64748b; font-size: 12px; padding: 6px 8px; text-decoration: none; }
.admin-back:hover { color: #cbd5e1; }

/* -------------------------------------------------------------------------- */
/* Main column                                                                 */
/* -------------------------------------------------------------------------- */
.admin-main { padding: 24px 32px 64px; min-width: 0; }
.admin-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 0 24px; border-bottom: 1px solid var(--line); margin-bottom: 28px;
}
.admin-page-title { font-size: 24px; margin: 0; font-weight: 700; }

.admin-alert {
    padding: 12px 16px; border-radius: 8px; margin-bottom: 20px;
    border-left: 3px solid;
}
.admin-alert--success { background: #f0fdf4; border-color: var(--success); color: #166534; }
.admin-alert--error   { background: #fef2f2; border-color: var(--danger);  color: #991b1b; }

.admin-content { display: grid; gap: 28px; }

/* -------------------------------------------------------------------------- */
/* Stats / dashboard                                                           */
/* -------------------------------------------------------------------------- */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
@media (max-width: 1100px) { .stats-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px)  { .stats-grid { grid-template-columns: 1fr; } }

.stat {
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    padding: 22px; display: flex; flex-direction: column; gap: 6px;
}
.stat-label { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 32px; font-weight: 700; letter-spacing: -.02em; }
.stat-link  { font-size: 13px; color: var(--primary); text-decoration: none; margin-top: auto; }
.stat--success .stat-value { color: var(--success); }

.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }

.panel {
    background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 22px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.panel-head h2 { margin: 0; font-size: 16px; }

/* -------------------------------------------------------------------------- */
/* Tables                                                                      */
/* -------------------------------------------------------------------------- */
.data-table {
    width: 100%; border-collapse: collapse; font-size: 14px;
}
.data-table th, .data-table td {
    padding: 12px 12px; text-align: left;
    border-bottom: 1px solid var(--line);
}
.data-table th {
    color: var(--muted); font-weight: 600; font-size: 12px;
    text-transform: uppercase; letter-spacing: .04em;
    background: #f8fafc;
}
.data-table tbody tr:hover { background: #fafbff; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table code { background: #f1f5f9; padding: 1px 6px; border-radius: 4px; font-size: 12px; }

.btn--sm { padding: 6px 12px; font-size: 13px; }

/* status pills */
.pill {
    display: inline-block; padding: 2px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
}
.pill--active   { background: #d1fae5; color: #065f46; }
.pill--suspended{ background: #fef3c7; color: #92400e; }
.pill--revoked  { background: #fee2e2; color: #991b1b; }
.pill--issued   { background: #ede9fe; color: #5b21b6; }
.pill--replaced { background: #f1f5f9; color: #475569; }

/* -------------------------------------------------------------------------- */
/* Audit list                                                                  */
/* -------------------------------------------------------------------------- */
.audit-list { list-style: none; padding: 0; margin: 0; }
.audit-list li {
    padding: 10px 0; border-bottom: 1px solid var(--line);
    display: flex; gap: 10px; flex-wrap: wrap; font-size: 13px;
}
.audit-list li:last-child { border-bottom: 0; }
.audit-time { color: var(--muted); font-family: Consolas, monospace; }
.audit-action { color: var(--ink); font-weight: 600; }
.audit-actor { color: var(--muted); }

/* -------------------------------------------------------------------------- */
/* Forms                                                                       */
/* -------------------------------------------------------------------------- */
.form-card {
    background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px;
    max-width: 760px;
}
.form-card .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 600px) { .form-card .form-row { grid-template-columns: 1fr; } }
.form-card label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: 16px; }
.form-card input, .form-card select, .form-card textarea {
    border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px;
    font: inherit; color: var(--ink); background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
.form-card input:focus, .form-card select:focus, .form-card textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.18);
}
.form-card .field-help { color: var(--muted); font-size: 12px; font-weight: 400; }
.form-card .field-error { color: var(--danger); font-size: 12px; font-weight: 500; }
.form-card .checkbox-group {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px;
    background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 12px;
}
.form-card .checkbox-group label {
    flex-direction: row; align-items: center; gap: 8px;
    margin-bottom: 0; font-weight: 500; font-size: 14px;
}
.form-card .checkbox-group input { width: auto; }

.form-actions {
    display: flex; gap: 10px; margin-top: 18px;
    padding-top: 18px; border-top: 1px solid var(--line);
}

/* -------------------------------------------------------------------------- */
/* Auth (login screens)                                                       */
/* -------------------------------------------------------------------------- */
.auth-shell {
    min-height: 100vh; display: grid; place-items: center;
    background:
        radial-gradient(800px 600px at 30% 20%, rgba(139,92,246,.15), transparent 60%),
        radial-gradient(800px 600px at 70% 80%, rgba(99,102,241,.18), transparent 60%),
        #0f172a;
    padding: 24px;
}
.auth-card {
    background: #fff; padding: 40px 36px; border-radius: 16px;
    width: 100%; max-width: 420px;
    box-shadow: 0 30px 80px -20px rgba(15,23,42,.5);
}
.auth-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; margin-bottom: 24px; color: var(--ink); }
.auth-brand small { color: var(--primary-2); font-weight: 500; }
.auth-card h1 { font-size: 24px; margin: 0 0 8px; }
.auth-card .form-error { margin-bottom: 16px; }
.auth-form { display: grid; gap: 14px; margin-top: 24px; }
.auth-form label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.auth-form input {
    border: 1px solid var(--line-2); border-radius: 8px; padding: 11px 14px;
    font: inherit;
}
.auth-form input:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.18);
}
.auth-foot { margin-top: 20px; text-align: center; }

/* -------------------------------------------------------------------------- */
/* Filter / search bar                                                         */
/* -------------------------------------------------------------------------- */
.filter-bar {
    display: flex; gap: 8px; padding: 14px 16px;
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
    margin-bottom: 16px;
}
.filter-bar input, .filter-bar select {
    border: 1px solid var(--line-2); border-radius: 7px; padding: 8px 10px; font: inherit;
}
.filter-bar input { flex-grow: 1; }
.filter-bar .btn { padding: 8px 14px; }

.pagination {
    display: flex; gap: 6px; justify-content: center; margin-top: 18px;
}
.pagination a, .pagination span {
    padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px;
    color: var(--ink); text-decoration: none; font-size: 14px; background: #fff;
}
.pagination a:hover { background: #f8fafc; }
.pagination .is-active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* -------------------------------------------------------------------------- */
/* Detail panes                                                                */
/* -------------------------------------------------------------------------- */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
@media (max-width: 1000px) { .detail-grid { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 8px 12px; }
.kv dt { color: var(--muted); font-size: 13px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv dd { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv dt:last-of-type, .kv dd:last-of-type { border-bottom: 0; }
.kv code { background: #f1f5f9; padding: 1px 6px; border-radius: 4px; font-size: 13px; }

.token-block {
    background: #0f172a; color: #e2e8f0; border-radius: 10px; padding: 16px;
    font-family: Consolas, 'JetBrains Mono', monospace; font-size: 12px;
    word-break: break-all; line-height: 1.55; max-height: 220px; overflow: auto;
}

/* -------------------------------------------------------------------------- */
/* Customer portal                                                            */
/* -------------------------------------------------------------------------- */
.portal-body {
    background: #f8fafc; min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto;
}
.portal-topbar {
    background: #fff; border-bottom: 1px solid var(--line); padding: 14px 0;
}
.portal-topbar-inner { display: flex; align-items: center; justify-content: space-between; }
.portal-main { padding: 36px 0 80px; }
.portal-greeting { font-size: 22px; margin: 0 0 24px; }
.portal-card {
    background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 24px;
    margin-bottom: 18px;
}
.portal-card h2 { margin: 0 0 12px; font-size: 18px; }
.portal-license-list { display: grid; gap: 12px; }
.portal-license {
    display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center;
    padding: 14px 18px;
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
    transition: box-shadow .15s, border-color .15s;
}
.portal-license:hover { border-color: var(--primary-3); box-shadow: var(--shadow); }
.portal-license-key { font-family: Consolas, monospace; font-weight: 600; color: var(--ink); }
.portal-license-meta { color: var(--muted); font-size: 14px; }

.upload-zone {
    border: 2px dashed var(--line-2); border-radius: 12px;
    background: #fafbff; padding: 32px;
    text-align: center; transition: border-color .15s, background .15s;
}
.upload-zone:hover { border-color: var(--primary); background: #f4f4ff; }
.upload-zone input[type=file] { display: block; margin: 12px auto; }

/* =============================================================================
   Mobile / responsive — admin & customer portal
   ============================================================================= */

/* Tables with many columns: allow horizontal scroll inside their card so the
   whole admin layout never grows past the viewport. Used by markup that wraps
   <table class="data-table"> in <div class="table-wrap">. */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table-wrap .data-table {
    min-width: 640px; /* keeps columns legible while scrolling */
}

@media (max-width: 880px) {
    .admin-sidebar {
        position: relative; height: auto; min-height: 0;
        flex-direction: row; flex-wrap: wrap; align-items: center;
        padding: 12px 16px;
    }
    .admin-sidebar .brand--admin { margin-bottom: 0; flex-shrink: 0; }
    .admin-nav {
        flex-direction: row; flex-wrap: wrap; gap: 4px;
        flex-grow: 1; min-width: 0;
    }
    .admin-nav a { padding: 8px 12px; font-size: 13px; }
    .admin-nav a.is-active { box-shadow: none; background: rgba(99,102,241,.25); }
    .admin-sidebar-footer {
        flex-direction: row; align-items: center; gap: 12px;
        border-top: 0; padding-top: 0; margin-left: auto;
    }
    .admin-user { display: none; }
    .admin-back { display: none; }

    .admin-main { padding: 18px 18px 48px; }
    .admin-topbar {
        flex-direction: column; align-items: stretch; gap: 12px;
        padding: 4px 0 16px;
    }
    .admin-page-title { font-size: 20px; }

    /* Filter / search bar collapses to vertical stack. */
    .filter-bar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
    .filter-bar input { flex-basis: 100%; }

    /* Form actions wrap so the buttons don't push beyond viewport. */
    .form-actions { flex-wrap: wrap; }
    .form-card { padding: 22px; }

    /* Customer portal license rows — stack vertically. */
    .portal-license {
        grid-template-columns: 1fr; gap: 8px; padding: 14px;
    }
    .portal-license-meta { font-size: 13px; }
}

@media (max-width: 600px) {
    .admin-sidebar { padding: 10px 12px; }
    .admin-nav a { padding: 6px 10px; font-size: 12px; }

    .admin-main { padding: 14px 14px 40px; }
    .admin-topbar h1 { font-size: 18px; }

    /* Stats cards — slightly tighter padding on phones. */
    .stat { padding: 16px; }
    .stat-value { font-size: 26px; }

    /* KV definition list (admin detail panes) collapses to single column. */
    .kv { grid-template-columns: 1fr; gap: 0 0; }
    .kv dt { padding: 8px 0 2px; border-bottom: 0; }
    .kv dd { padding: 0 0 8px; border-bottom: 1px solid var(--line); }

    /* Auth card already responsive via site.css; sharpen further on phones. */
    .auth-shell { padding: 16px; }
    .auth-card h1 { font-size: 20px; }

    /* Audit list — wrap tighter, smaller meta. */
    .audit-list li { gap: 6px; font-size: 12px; }

    /* Token block — phones can't show all 1k characters comfortably; cap height. */
    .token-block { font-size: 11px; max-height: 160px; }

    .pagination a, .pagination span { padding: 5px 9px; font-size: 13px; }
}

/* -------------------------------------------------------------------------- */
/* Tablet / touch — comfortable tap targets and iOS Safari zoom guard         */
/*                                                                            */
/* iPad portrait (768) and landscape (1024) fall through the desktop layout,  */
/* so without this block inputs render at ~40px and inherit the body's        */
/* default font size — both below Apple HIG's 44 pt touch target and below    */
/* the 16 px threshold that stops iOS Safari from auto-zooming on focus.      */
/* min-width:601 keeps the phone-specific overrides above intact.             */
/* -------------------------------------------------------------------------- */
@media (min-width: 601px) and (max-width: 1024px) {
    .auth-form input,
    .form-card input,
    .form-card select,
    .form-card textarea,
    .filter-bar input,
    .filter-bar select {
        font-size: 16px;
        padding: 12px 14px;
    }

    /* Keep the comfortable login-button padding even on tablets where the
       720px phone media query in site.css would otherwise shrink it. */
    .auth-form .btn--lg { padding: 14px 22px; font-size: 16px; }

    /* Admin sidebar in horizontal mode (≤880) — bump the nav links so they're
       reliably tappable rather than tightly packed. */
    .admin-nav a { padding: 11px 14px; font-size: 14px; }
}
