:root {
    --bg-start: #eaf3fb;
    --bg-end: #f6fafe;
    --brand-blue: #2f7df4;
    --brand-blue-hover: #2563d6;
    --text-dark: #14213d;
    --text-muted: #6b7891;
    --border-soft: #d9e3ef;
    --card-bg: #ffffff;
    --row-hover: #f3f8ff;
    --pill-green: #c6f1d2;
    --pill-green-text: #156a36;
    --pill-red: #fde4e4;
    --pill-red-text: #b3261e;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background: linear-gradient(180deg, var(--bg-start) 0%, var(--bg-end) 70%);
    color: var(--text-dark);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
}

.page-shell {
    max-width: min(96vw, 2400px);
    margin: 0 auto;
    padding: 0.5rem 1.5rem 3rem 1.5rem;
}

.brand-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.25rem 0 1rem 0;
}
.brand-logo {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
}
.brand-img {
    height: 56px;
    width: auto;
    display: block;
}
.brand-name {
    font-size: 2.6rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-dark);
    line-height: 1;
}

.toolbar-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin: 0.5rem 0 1rem 0;
}

.tb-btn {
    background: var(--brand-blue);
    border-color: var(--brand-blue);
    color: #fff;
    font-weight: 600;
    padding: 0.55rem 1.1rem;
    border-radius: 8px;
    font-size: 0.92rem;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.tb-btn:hover { background: var(--brand-blue-hover); border-color: var(--brand-blue-hover); color: #fff; }
.tb-btn-light {
    background: #eef2f7;
    color: #1f2937;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-weight: 600;
}
.tb-logout { margin-left: auto; }

.tb-input {
    width: auto;
    min-width: 180px;
    padding: 0.55rem 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--border-soft);
    background: #fff;
    font-size: 0.9rem;
    color: var(--text-dark);
}

#link-output { flex: 1; min-width: 240px; max-width: 360px; }

.entries-summary {
    margin: 0 0 0.6rem 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.table-card {
    background: var(--card-bg);
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    padding: 1rem 1rem 0.5rem 1rem;
    box-shadow: 0 4px 20px rgba(40, 80, 140, 0.05);
}

table#offers-table thead th {
    background: transparent;
    color: var(--text-dark);
    font-weight: 700;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border-soft);
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    vertical-align: middle;
}

table#offers-table tbody tr {
    background: #f6f9fd;
    border-radius: 12px;
}
table#offers-table tbody tr:nth-child(even) { background: #ffffff; }
table#offers-table tbody td {
    border-top: 1px solid transparent;
    vertical-align: middle;
    font-size: 0.88rem;
    padding: 1rem 0.6rem;
    color: #2a3344;
}

.column-filter-row th { padding-top: 0; padding-bottom: 0.5rem; }
.column-filter-row input {
    width: 100%;
    padding: 0.35rem 0.55rem;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    background: #f6f9fd;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.pill {
    display: inline-block;
    padding: 0.3rem 0.85rem;
    border-radius: 8px;
    background: var(--pill-green);
    color: var(--pill-green-text);
    font-weight: 600;
    font-size: 0.85rem;
}

.row-btn {
    background: var(--brand-blue);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}
.row-btn:hover { background: var(--brand-blue-hover); color: #fff; }
.row-btn-link { text-decoration: none; }

.cell-multiline {
    white-space: pre-line;
    line-height: 1.35;
    display: inline-block;
    text-align: left;
    min-width: 120px;
}
.cell-muted { color: var(--text-muted); }

/* Red chips for the "Not Allowed Traffic Type" column. Each label stays on a
   single line (no mid-phrase wrapping); chips flow and wrap as a group. */
.cell-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.25rem;
    justify-content: flex-start;
    max-width: 280px;
}
.pill-deny {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 6px;
    background: var(--pill-red);
    color: var(--pill-red-text);
    font-weight: 600;
    font-size: 0.7rem;
    line-height: 1.4;
    white-space: nowrap;
}

.dataTables_wrapper .dataTables_filter input { border: 1px solid var(--border-soft); border-radius: 6px; }
.dataTables_wrapper .dataTables_length select { border: 1px solid var(--border-soft); border-radius: 6px; }
.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 6px !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--brand-blue) !important;
    color: #fff !important;
    border-color: var(--brand-blue) !important;
}

/* Modals */
.modal-content {
    border-radius: 14px;
    border: none;
    box-shadow: 0 25px 60px rgba(20, 33, 61, 0.15);
}
.modal-corner-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 1;
}
.modal-title-large {
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--text-dark);
    margin-bottom: 1rem;
}
.description-body {
    background: #f6f9fd;
    border-radius: 10px;
    padding: 1rem 1.25rem;
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.95rem;
    color: #2a3344;
    margin: 0;
    max-height: 55vh;
    overflow-y: auto;
}
.gl-error { color: #b91c1c; font-size: 0.85rem; min-height: 1.1rem; }

@media (max-width: 1280px) {
    .tb-logout { margin-left: 0; }
}

/* ---------- header user chip ---------- */
.brand-bar {
    justify-content: space-between;
}
.brand-logo { text-decoration: none; color: inherit; }
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    background: #ffffff;
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    padding: 0.35rem 0.85rem;
    font-size: 0.88rem;
    color: var(--text-dark);
}
.user-chip i { font-size: 1.1rem; color: var(--brand-blue); }
.user-name { font-weight: 600; }
.user-role {
    font-size: 0.72rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #eef2f7;
    color: var(--text-muted);
}
.role-admin { background: #fce7d2; color: #9a4a08; }
.role-viewer { background: #dbe7fa; color: #1f4ea3; }
.role-token { background: #f3e8ff; color: #6b21a8; }
.user-expiry { font-size: 0.78rem; color: var(--text-muted); }
.user-link {
    color: var(--brand-blue);
    text-decoration: none;
    font-weight: 600;
    border-left: 1px solid var(--border-soft);
    padding-left: 0.6rem;
}
.user-link:hover { color: var(--brand-blue-hover); }

/* ---------- login ---------- */
.login-shell {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}
.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 2rem 2.25rem;
    box-shadow: 0 12px 40px rgba(40, 80, 140, 0.08);
    border: 1px solid var(--border-soft);
    width: 100%;
    max-width: 380px;
}
.login-title {
    font-weight: 800;
    margin-bottom: 1.25rem;
    text-align: center;
    color: var(--text-dark);
}
.login-error {
    background: #fde8e8;
    color: #991b1b;
    border-radius: 8px;
    padding: 0.55rem 0.85rem;
    margin-bottom: 1rem;
    font-size: 0.88rem;
}

/* ---------- admin ---------- */
.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.88rem;
}
.back-link:hover { color: var(--brand-blue); }

.page-section-title {
    font-size: 1.6rem;
    font-weight: 800;
    margin: 0.75rem 0 1.25rem 0;
    color: var(--text-dark);
}

.admin-grid {
    display: grid;
    gap: 1.5rem;
}

.admin-card {
    background: var(--card-bg);
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    padding: 1.25rem 1.25rem;
    box-shadow: 0 4px 20px rgba(40, 80, 140, 0.05);
}
.admin-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.admin-card-head h3 {
    margin: 0;
    font-weight: 700;
    font-size: 1.2rem;
}

.admin-table thead th {
    background: transparent;
    border-bottom: 1px solid var(--border-soft);
    font-weight: 700;
    color: var(--text-dark);
    font-size: 0.85rem;
}
.admin-table tbody td { vertical-align: middle; font-size: 0.9rem; }
.role-select { width: auto; min-width: 110px; display: inline-block; }
.token-cell code {
    background: #f1f5fb;
    border-radius: 4px;
    padding: 0.15rem 0.4rem;
}

.state-pill {
    display: inline-block;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.state-active { background: var(--pill-green); color: var(--pill-green-text); }
.state-expired { background: #f3f4f6; color: #4b5563; }
.state-revoked { background: #fde8e8; color: #991b1b; }

/* ============================================================
   Responsive / mobile
   ============================================================ */

/* The offers table is wide (13 columns). Rather than crush columns on
   small screens, let the card scroll horizontally with a momentum swipe. */
.table-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 992px) {
    .page-shell { padding: 0.5rem 1rem 2.5rem 1rem; }
    .brand-img { height: 46px; }
    .tb-logout { margin-left: 0; }
}

@media (max-width: 768px) {
    body { font-size: 13px; }
    .page-shell { padding: 0.5rem 0.75rem 2.5rem 0.75rem; }

    /* Header stacks: logo on top, account chip below, both centered. */
    .brand-bar { flex-direction: column; gap: 0.65rem; padding: 0.85rem 0 0.5rem; }
    .brand-img { height: 40px; }
    .user-chip {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.4rem 0.6rem;
        font-size: 0.8rem;
        padding: 0.35rem 0.7rem;
    }
    .user-link { border-left: none; padding-left: 0; }

    /* Toolbar: ~2 buttons per row, inputs full width, bigger tap targets. */
    .toolbar-row { gap: 0.5rem; margin-bottom: 0.85rem; }
    .toolbar-row .tb-btn,
    .toolbar-row .tb-btn-light {
        flex: 1 1 45%;
        justify-content: center;
        padding: 0.7rem 0.8rem;
        font-size: 0.92rem;
    }
    .toolbar-row .tb-input,
    .toolbar-row .form-select,
    #link-output {
        flex: 1 1 100%;
        width: 100%;
        min-width: 0;
        max-width: none;
    }
    .tb-logout { flex: 1 1 100%; }

    .entries-summary { text-align: center; }

    /* Table swipes sideways (handled by DataTables scrollX). */
    .table-card { padding: 0.75rem 0.5rem 0.4rem; border-radius: 12px; }

    /* DataTables top controls stack and go full width. */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none;
        text-align: left;
        width: 100%;
        margin-bottom: 0.5rem;
    }
    .dataTables_wrapper .dataTables_filter label {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.3rem;
        width: 100%;
    }
    .dataTables_wrapper .dataTables_filter input { width: 100%; margin: 0; }

    /* Modals hug the screen. */
    .modal-dialog { margin: 0.5rem; }
    .modal-title-large { font-size: 1.2rem; }

    /* Admin tables scroll too. */
    .admin-card { overflow-x: auto; }
    .page-section-title { font-size: 1.3rem; }
}

@media (max-width: 480px) {
    .brand-img { height: 34px; }
    /* One button per row on very small phones. */
    .toolbar-row .tb-btn,
    .toolbar-row .tb-btn-light { flex: 1 1 100%; }
    .modal-title-large { font-size: 1.1rem; }
}

