/* ============================================
   AffiliateTracker - Main Light Theme Stylesheet
   ============================================ */

:root {
    --primary:      #4F46E5;
    --primary-dark: #4338CA;
    --primary-light:#EEF2FF;
    --secondary:    #10B981;
    --warning:      #F59E0B;
    --danger:       #EF4444;
    --info:         #3B82F6;
    --bg:           #F8FAFC;
    --sidebar-bg:   #FFFFFF;
    --card-bg:      #FFFFFF;
    --border:       #E2E8F0;
    --text:         #1E293B;
    --text-muted:   #64748B;
    --text-light:   #94A3B8;
    --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
    --radius:       10px;
    --radius-sm:    6px;
    --sidebar-w:    250px;
    --topbar-h:     64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.65;
}

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

/* ── Layout ── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 100;
    transition: width .25s;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: 24px;
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 16px;
    color: var(--primary);
    text-decoration: none;
}
.sidebar-logo .logo-icon {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 18px;
    flex-shrink: 0;
}
.sidebar-section {
    padding: 12px 12px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-light);
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin: 1px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    transition: .15s;
    text-decoration: none;
}
.nav-link:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.nav-link.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-link svg { flex-shrink: 0; width: 16px; height: 16px; }
.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 20px;
}

/* ── Main content ── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.notification-btn {
    position: relative;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: .15s;
}
.notification-btn:hover { background: var(--primary-light); color: var(--primary); }
.notif-badge {
    position: absolute;
    top: -2px; right: -2px;
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    width: 16px; height: 16px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}
.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--radius);
    background: var(--bg);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    transition: .15s;
    position: relative;
}
.user-menu:hover { border-color: var(--primary); }
.user-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    display: flex; align-items: center; justify-content: center;
}
.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 160px;
    display: none;
    z-index: 200;
    overflow: hidden;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    font-size: 13px;
    color: var(--text);
    transition: .1s;
    text-decoration: none;
}
.dropdown-item:hover { background: var(--bg); text-decoration: none; }
.dropdown-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ── Page body ── */
.page-body {
    padding: 24px;
    flex: 1;
}

/* ── Page header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}
.page-header p {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Stat cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--shadow);
    transition: .2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-sub { font-size: 13px; color: var(--text-light); }
.stat-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    margin-bottom: 8px;
    align-self: flex-start;
}
.stat-icon.blue   { background: #EFF6FF; color: #2563EB; }
.stat-icon.green  { background: #F0FDF4; color: #16A34A; }
.stat-icon.orange { background: #FFF7ED; color: #EA580C; }
.stat-icon.purple { background: #F5F3FF; color: #7C3AED; }
.stat-icon.red    { background: #FEF2F2; color: #DC2626; }
.stat-icon.teal   { background: #F0FDFA; color: #0F766E; }

/* ── Cards ── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}
.card-body { padding: 20px; }
.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    font-size: 13px;
    color: var(--text-muted);
}

/* ════════════════════════════════════════
   MODERN TABLE SYSTEM
   ════════════════════════════════════════ */

/* ── Wrapper ── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── Base table ── */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

/* ── Header ── */
thead tr {
    background: linear-gradient(135deg, #F0F4FF 0%, #EAF0FF 100%);
}
thead th {
    padding: 14px 18px;
    text-align: left;
    font-weight: 700;
    color: #4338CA;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .09em;
    border-bottom: 2px solid #DDE4F9;
    white-space: nowrap;
    position: relative;
    user-select: none;
    transition: color .15s, background .15s;
}
thead th:first-child { padding-left: 22px; border-radius: 0; }
thead th:last-child  { padding-right: 22px; }

/* ── DataTables sort icons ── */
thead th.sorting,
thead th.sorting_asc,
thead th.sorting_desc {
    cursor: pointer;
    padding-right: 30px;
}
thead th.sorting::after,
thead th.sorting_asc::after,
thead th.sorting_desc::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    background-size: 14px;
    background-repeat: no-repeat;
    background-position: center;
    opacity: .35;
    transition: opacity .15s;
}
thead th.sorting::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%234338CA' stroke-width='2.5'%3E%3Cpath d='M7 15l5 5 5-5M7 9l5-5 5 5'/%3E%3C/svg%3E");
}
thead th.sorting_asc::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%234338CA' stroke-width='2.5'%3E%3Cpath d='M7 15l5 5 5-5'/%3E%3C/svg%3E");
    opacity: 1;
}
thead th.sorting_desc::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%234338CA' stroke-width='2.5'%3E%3Cpath d='M7 9l5-5 5 5'/%3E%3C/svg%3E");
    opacity: 1;
}
thead th:hover.sorting,
thead th:hover.sorting_asc,
thead th:hover.sorting_desc {
    color: #3730A3;
    background: #E5EDFF;
}
thead th:hover.sorting::after,
thead th:hover.sorting_asc::after,
thead th:hover.sorting_desc::after { opacity: 1; }

/* ── Body rows ── */
tbody td {
    padding: 14px 18px;
    border-bottom: 1px solid #F1F5FB;
    color: var(--text);
    vertical-align: middle;
    transition: background .1s;
}
tbody td:first-child { padding-left: 22px; }
tbody td:last-child  { padding-right: 22px; }

/* Zebra rows */
tbody tr:nth-child(even) td { background: #F8FAFF; }
tbody tr:nth-child(odd)  td { background: #FFFFFF; }

/* Hover */
tbody tr { position: relative; }
tbody tr:hover td { background: #EEF2FF !important; }
tbody tr:hover td:first-child { box-shadow: inset 3px 0 0 #4F46E5; }
tbody tr:last-child td { border-bottom: none; }

/* ── Column types ── */
td.col-num, th.col-num { text-align: right; }
td.col-center, th.col-center { text-align: center; }
td.col-mono { font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace; font-size: 12.5px; }

/* ── Text helpers inside tables ── */
.tbl-primary   { font-weight: 700; color: var(--text); font-size: 14px; }
.tbl-secondary { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.tbl-code      { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; background: #EEF2FF; color: #4F46E5; padding: 2px 8px; border-radius: 5px; display: inline-block; letter-spacing: .02em; border: 1px solid #DDE3F7; }

/* ── Action cell ── */
.tbl-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ── No-data row ── */
tbody tr.no-data td,
.dataTables_empty {
    text-align: center;
    padding: 56px 20px !important;
    color: var(--text-muted) !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    background: #fff !important;
    box-shadow: none !important;
}
.dataTables_empty::before {
    content: '';
    display: block;
    width: 48px;
    height: 48px;
    margin: 0 auto 14px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24' fill='none' stroke='%23C7D2FE' stroke-width='1.5'%3E%3Cellipse cx='12' cy='5' rx='9' ry='3'/%3E%3Cpath d='M21 12c0 1.66-4.03 3-9 3S3 13.66 3 12'/%3E%3Cpath d='M3 5v14c0 1.66 4.03 3 9 3s9-1.34 9-3V5'/%3E%3C/svg%3E") no-repeat center;
    background-size: 48px;
    opacity: .6;
}

/* ── Card + table: clip rounded corners ── */
.card .table-wrap {
    border-radius: 0 0 var(--radius) var(--radius);
    overflow: hidden;
}
.card .table-wrap table {
    border-radius: 0;
}

/* ════════════════════════════════════════
   DATATABLES OVERRIDES — MODERN TOOLBAR
   ════════════════════════════════════════ */

.dataTables_wrapper {
    font-size: 13px;
}

/* Wrapper gets a subtle premium border */
.card .dataTables_wrapper {
    border-radius: var(--radius);
}

/* ── Top toolbar (length + search) ── */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    padding: 14px 22px 12px;
    background: #FAFBFF;
}
.dataTables_wrapper .dataTables_length { float: left; }
.dataTables_wrapper .dataTables_filter { float: right; }

.dataTables_wrapper .dataTables_length label,
.dataTables_wrapper .dataTables_filter label {
    font-size: 12.5px;
    font-weight: 600;
    color: #64748B;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    letter-spacing: .01em;
}

/* Show N entries select */
.dataTables_wrapper .dataTables_length select {
    padding: 7px 30px 7px 12px;
    border: 1.5px solid #E2E8F0;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    background: #F8FAFC url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%234F46E5' fill='none' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 10px center;
    appearance: none;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s, background .15s;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.dataTables_wrapper .dataTables_length select:hover {
    border-color: #A5B4FC;
    background-color: #fff;
}
.dataTables_wrapper .dataTables_length select:focus {
    outline: none;
    border-color: #4F46E5;
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

/* Search input */
.dataTables_wrapper .dataTables_filter input {
    padding: 8px 14px 8px 36px;
    border: 1.5px solid #E2E8F0;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    background: #F8FAFC url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%234F46E5' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='M21 21l-4.35-4.35'/%3E%3C/svg%3E") no-repeat 11px center;
    transition: border-color .15s, box-shadow .15s, width .2s, background .15s;
    width: 200px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.dataTables_wrapper .dataTables_filter input:hover {
    border-color: #A5B4FC;
    background-color: #fff;
}
.dataTables_wrapper .dataTables_filter input:focus {
    outline: none;
    border-color: #4F46E5;
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
    width: 250px;
}
.dataTables_wrapper .dataTables_filter input::placeholder { color: #94A3B8; }

/* Divider between toolbar and table */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    border-bottom: 1px solid #EEF2FF;
    padding-bottom: 12px;
}

/* Clear floats */
.dataTables_wrapper::after { content: ''; display: table; clear: both; }

/* ── Bottom bar (info + pagination) ── */
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    padding: 14px 22px;
    font-size: 12.5px;
    color: #94A3B8;
    font-weight: 500;
    background: linear-gradient(135deg, #F8FAFF 0%, #F5F7FF 100%);
    border-top: 1px solid #EEF2FF;
}
.dataTables_wrapper .dataTables_info { float: left; line-height: 32px; }
.dataTables_wrapper .dataTables_paginate { float: right; }
.dataTables_wrapper .dataTables_paginate::after { content: ''; display: table; clear: both; }

/* Pagination buttons */
.dataTables_wrapper .dataTables_paginate .paginate_button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: #64748B !important;
    cursor: pointer;
    border: 1.5px solid transparent !important;
    margin: 0 2px;
    transition: all .15s;
    background: transparent !important;
    box-shadow: none !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover:not(.disabled) {
    background: #EEF2FF !important;
    color: #4F46E5 !important;
    border-color: #C7D2FE !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: linear-gradient(135deg, #4F46E5, #6D28D9) !important;
    color: #fff !important;
    border-color: transparent !important;
    box-shadow: 0 2px 8px rgba(79,70,229,.35) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
    color: #CBD5E1 !important;
    cursor: not-allowed;
    background: transparent !important;
}
/* Previous / Next pill style */
.dataTables_wrapper .dataTables_paginate .paginate_button.previous,
.dataTables_wrapper .dataTables_paginate .paginate_button.next {
    padding: 0 14px;
    border: 1.5px solid #E2E8F0 !important;
    background: #fff !important;
    color: #475569 !important;
    font-weight: 600;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.previous:hover:not(.disabled),
.dataTables_wrapper .dataTables_paginate .paginate_button.next:hover:not(.disabled) {
    background: #EEF2FF !important;
    border-color: #A5B4FC !important;
    color: #4F46E5 !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.previous.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.next.disabled {
    border-color: #F1F5F9 !important;
    background: #FAFAFA !important;
    color: #CBD5E1 !important;
}
.dataTables_wrapper .dataTables_paginate .ellipsis {
    color: #94A3B8;
    padding: 0 4px;
    line-height: 32px;
    display: inline-block;
}

/* ── Responsive ── */
@media (max-width: 640px) {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter { float: none; padding: 12px 16px 10px; }
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate { float: none; padding: 10px 16px; text-align: center; }
    .dataTables_wrapper .dataTables_filter input { width: 100%; }
    .dataTables_wrapper .dataTables_filter input:focus { width: 100%; }
    thead th { padding: 11px 12px; font-size: 10.5px; }
    tbody td  { padding: 12px 12px; font-size: 13px; }
    thead th:first-child, tbody td:first-child { padding-left: 14px; }
    thead th:last-child,  tbody td:last-child  { padding-right: 14px; }
}
@media (max-width: 360px) {
    thead th { padding: 9px 10px; font-size: 10px; }
    tbody td  { padding: 9px 10px; font-size: 12px; }
}

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    line-height: 1;
    white-space: nowrap;
}
.badge-success { background: #DCFCE7; color: #15803D; border: 1px solid #BBF7D0; }
.badge-warning { background: #FEF9C3; color: #92400E; border: 1px solid #FDE68A; }
.badge-danger  { background: #FEE2E2; color: #B91C1C; border: 1px solid #FECACA; }
.badge-info    { background: #DBEAFE; color: #1D4ED8; border: 1px solid #BFDBFE; }
.badge-muted   { background: #F1F5F9; color: #475569; border: 1px solid #E2E8F0; }
.badge-purple  { background: #F3E8FF; color: #7E22CE; border: 1px solid #E9D5FF; }
.badge-orange  { background: #FFF7ED; color: #C2410C; border: 1px solid #FED7AA; }
/* Dot indicator on badges */
.badge::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}
.badge.no-dot::before { display: none; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: .15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-success   { background: var(--secondary); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-sm        { padding: 6px 14px; font-size: 13px; }
.btn-icon      { width: 34px; height: 34px; padding: 0; border-radius: var(--radius-sm); }

/* ── Forms ── */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text);
    background: #fff;
    transition: .15s;
    appearance: none;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
.form-control::placeholder { color: var(--text-light); }
select.form-control { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748B' fill='none' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
textarea.form-control { min-height: 100px; resize: vertical; }
.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 4px; }
.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.form-check input { width: 16px; height: 16px; accent-color: var(--primary); }

/* ── Alerts ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.alert-success { background: #F0FDF4; color: #15803D; border: 1px solid #BBF7D0; }
.alert-error   { background: #FEF2F2; color: #DC2626; border: 1px solid #FECACA; }
.alert-warning { background: #FFFBEB; color: #92400E; border: 1px solid #FDE68A; }
.alert-info    { background: #EFF6FF; color: #1D4ED8; border: 1px solid #BFDBFE; }

/* ── Grid layouts ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }

/* ── Utils ── */
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.fw-bold { font-weight: 700; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* ── Copy input ── */
.copy-group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.copy-group .form-control { flex: 1; min-width: 140px; font-family: monospace; font-size: 12px; background: #F8FAFC; }
.copy-group .btn { flex-shrink: 0; white-space: nowrap; }

/* ── Charts ── */
.chart-container { position: relative; height: 260px; }

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 13px; }

/* ── Sidebar overlay (mobile) ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 99;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ── Mobile sidebar toggle button ── */
#sidebarToggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: .15s;
}
#sidebarToggle:hover { background: var(--primary-light); color: var(--primary); }

/* ── Dashboard-specific grids ── */
.dash-stat-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}
.dash-main-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 16px;
    margin-bottom: 20px;
}
.dash-kpi-stack { display: flex; flex-direction: column; gap: 12px; }
.dash-table-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}
.dash-stat-card {
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 18px 16px;
    overflow: hidden;
}
.dash-stat-label {
    font-size: 11px;
    font-weight: 700;
    color: #9CA3AF;
    letter-spacing: .08em;
    text-transform: uppercase;
    margin-bottom: 6px;
}
.dash-stat-value {
    font-size: 30px;
    font-weight: 800;
    color: #111827;
    line-height: 1;
}
.dash-kpi-card {
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 15px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
}
.dash-kpi-icon {
    width: 46px; height: 46px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.dash-kpi-value {
    font-size: 20px;
    font-weight: 800;
    color: #111827;
    line-height: 1.2;
}
.dash-kpi-sub { font-size: 13px; color: #9CA3AF; margin-top: 2px; }
.dash-filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.dash-date-input {
    display: flex;
    align-items: center;
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
}
.dash-date-input input[type=date] {
    border: none;
    outline: none;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    background: transparent;
    min-width: 0;
}
.dash-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 14px;
}
.dash-page-title-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: 2px;
}
.dash-page-title {
    font-size: 26px;
    font-weight: 800;
    margin: 0;
    color: #111827;
}
.dash-mgr-banner {
    background: linear-gradient(135deg,#4F46E5,#7C3AED);
    border-radius: 10px;
    padding: 14px 20px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.dash-section-title {
    font-size: 16px;
    font-weight: 700;
    color: #111827;
    padding: 16px 20px;
    border-bottom: 1px solid #F3F4F6;
}
.dash-tbl-th {
    padding: 11px 18px;
    text-align: left;
    font-size: 11.5px;
    font-weight: 700;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: .06em;
    background: #F9FAFB;
}
.dash-tbl-td {
    padding: 12px 18px;
    font-size: 14px;
    color: #374151;
    border-top: 1px solid #F3F4F6;
}

/* ══════════════════════════════════════════
   RESPONSIVE — no horizontal scroll on any device
   ══════════════════════════════════════════ */

/* Prevent the whole page from scrolling left-right */
html { overflow-x: hidden; }
body { overflow-x: hidden; }
/* Do NOT put overflow on main-content — it would clip the topbar dropdown-menu.
   Horizontal overflow is already handled by html/body above and per-card table-wrap below. */
.main-content { min-width: 0; }

/* Any direct table inside a card scrolls horizontally within the card,
   not the whole page. This covers views that don't use .table-wrap */
.card > table,
.card > .card-body > table,
.card > form > table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

/* Every table lives inside a scrollable wrapper — only the table scrolls, not the page */
.table-wrap,
.dataTables_wrapper,
.card .table-wrap,
.card > .dataTables_wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}
/* DataTables generated wrapper */
.dataTables_wrapper { width: 100% !important; }
table { min-width: 0; }

/* Card header row wraps on narrow screens */
.card-header { flex-wrap: wrap; gap: 10px; }

/* Page header action buttons wrap */
.page-header { flex-wrap: wrap; gap: 12px; }
.page-header > *:last-child { flex-shrink: 0; }

/* ── 1100 px ── */
@media (max-width: 1100px) {
    .dash-stat-grid { grid-template-columns: repeat(3, 1fr); }
    .dash-main-grid { grid-template-columns: 1fr 300px; }
}

/* ── 900 px ── */
@media (max-width: 900px) {
    .dash-main-grid { grid-template-columns: 1fr; }
    .dash-kpi-stack { flex-direction: row; flex-wrap: wrap; }
    .dash-kpi-card  { flex: 1 1 calc(50% - 8px); min-width: 160px; }
}

/* ── 768 px (tablet / large phone) ── */
@media (max-width: 768px) {
    /* Show hamburger button */
    #sidebarToggle { display: flex; align-items: center; justify-content: center; }

    /* Sidebar slides in from left; hidden by default */
    .sidebar {
        transform: translateX(-100%);
        transition: transform .28s cubic-bezier(.4,0,.2,1);
        z-index: 200;
        box-shadow: none;
        width: min(280px, 82vw);
        height: 100vh;
        height: 100dvh;
        top: 0;
        bottom: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 6px 0 28px rgba(0,0,0,.18);
    }

    .main-content { margin-left: 0; }
    .topbar { padding: 0 12px; gap: 8px; }
    .topbar-title { font-size: 14px; }
    .user-menu span { display: none; }
    .user-menu { padding: 6px 8px; gap: 6px; }

    .page-body { padding: 14px; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .page-header .d-flex { flex-wrap: wrap; }
    .page-header h1 { font-size: 20px; }

    /* All multi-col grids collapse */
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }

    .card-body { padding: 14px; }
    .card-header { padding: 12px 14px; }

    /* DataTables controls wrap */
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: left !important;
        margin-bottom: 8px;
    }
    .dataTables_wrapper .dataTables_filter input { width: 100%; box-sizing: border-box; }

    /* Dashboard */
    .dash-stat-grid  { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .dash-table-grid { grid-template-columns: 1fr; }
    .dash-page-header { flex-direction: column; align-items: flex-start; }
    .dash-date-input  { width: 100%; flex-wrap: wrap; }
    .dash-filter-bar  { width: 100%; }
    .dash-mgr-banner  { flex-direction: column; align-items: flex-start; }
    .dash-stat-value  { font-size: 24px; }
    .dash-page-title  { font-size: 20px; }
    .dash-main-grid   { grid-template-columns: 1fr; }
}

/* ── 480 px (phone) ── */
@media (max-width: 480px) {
    .topbar { padding: 0 10px; gap: 6px; height: 56px; }
    --topbar-h: 56px;
    .topbar-title { font-size: 13px; }

    .page-body { padding: 10px; }
    .page-header h1 { font-size: 18px; }

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

    .btn { font-size: 13px; padding: 8px 12px; }
    .btn-sm { padding: 5px 10px; font-size: 12px; }

    .card-header { padding: 10px 12px; }
    .card-body   { padding: 12px; }
    .card-title  { font-size: 14px; }

    .form-group  { margin-bottom: 14px; }
    .form-control { font-size: 14px; padding: 9px 12px; }
    .form-group label { font-size: 13px; }

    /* Tables: smaller padding so more columns fit */
    thead th { padding: 10px 12px; font-size: 10.5px; letter-spacing: .05em; }
    tbody td  { padding: 11px 12px; font-size: 13px; }
    thead th:first-child, tbody td:first-child { padding-left: 14px; }
    thead th:last-child,  tbody td:last-child  { padding-right: 14px; }
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter { float: none; padding: 10px 14px 0; }
    .dataTables_wrapper .dataTables_filter input { width: 100%; }
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate { float: none; padding: 10px 14px; }

    /* Dashboard */
    .dash-stat-grid  { grid-template-columns: 1fr 1fr; gap: 8px; }
    .dash-stat-card  { padding: 14px 12px; }
    .dash-stat-value { font-size: 22px; }
    .dash-stat-label { font-size: 10px; }
    .dash-kpi-card   { flex: 1 1 100%; }
    .dash-kpi-value  { font-size: 16px; }
    .dash-tbl-td     { font-size: 13px; padding: 9px 12px; }
    .dash-tbl-th     { padding: 9px 12px; font-size: 10.5px; }

    .mgr-card        { margin: 8px 6px 12px; }
    .mgr-row-value   { font-size: 12px; max-width: 120px; }

    /* Sidebar narrower on tiny phones */
    .sidebar {
        width: min(260px, 86vw);
        height: 100vh;
        height: 100dvh;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    /* Badges / inline flex rows wrap */
    .d-flex { flex-wrap: wrap; }
    .topbar-actions { gap: 6px; }
}

/* ── 360 px (very small phones) ── */
@media (max-width: 360px) {
    .dash-stat-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
    .dash-stat-value { font-size: 20px; }
    .btn  { padding: 7px 10px; font-size: 12px; }
    .page-body { padding: 8px; }
}

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE FIXES — Mobile, Tablet, Desktop
   ══════════════════════════════════════════════════════════════════ */

/* ── Sidebar toggle: hidden on desktop, shown on mobile ── */
#sidebarToggle {
    display: none;
    background: none;
    border: none;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ── Sidebar overlay backdrop ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 199;
    -webkit-tap-highlight-color: transparent;
}
.sidebar-overlay.show { display: block; }

/* ── Cards: prevent overflow on small screens ── */
.card { overflow: hidden; }

/* ── All fixed-width inner elements — allow shrinking ── */
.form-control, select, textarea, input[type="text"],
input[type="email"], input[type="password"], input[type="number"],
input[type="url"], input[type="tel"] {
    max-width: 100%;
    box-sizing: border-box;
}

/* ── Tables: horizontal scroll instead of overflow ── */
.table-wrap, [style*="overflow-x:auto"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── Grid helpers ── */
.grid-2  { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3  { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.grid-4  { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
.pb-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Settings page max-width cards ── */
@media (max-width: 768px) {
    .card[style*="max-width"] { max-width: 100% !important; }
    div[style*="max-width:680px"],
    div[style*="max-width:780px"],
    div[style*="max-width:860px"] { max-width: 100% !important; }
}

/* ══ 1024px — Tablet landscape ══════════════════════════════════ */
@media (max-width: 1024px) {
    :root { --sidebar-w: 220px; }
    .grid-4 { grid-template-columns: repeat(2,1fr); }
    .grid-3 { grid-template-columns: repeat(2,1fr); }
}

/* ══ 768px — Tablet portrait / large phone ══════════════════════ */
@media (max-width: 768px) {
    /* Hamburger visible */
    #sidebarToggle { display: flex; align-items: center; justify-content: center; }

    /* Sidebar slides in */
    .sidebar {
        transform: translateX(-100%);
        transition: transform .28s cubic-bezier(.4,0,.2,1);
        z-index: 200;
        width: min(280px, 82vw);
        box-shadow: none;
        position: fixed;
        top: 0; left: 0; bottom: 0;
        height: 100vh; height: 100dvh;
        overflow-y: auto; overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 6px 0 32px rgba(0,0,0,.2);
    }
    .main-content { margin-left: 0; }

    /* Topbar */
    .topbar { padding: 0 12px; gap: 8px; }
    .topbar-title { font-size: 14px; }
    .user-menu span { display: none; }
    .user-menu { padding: 6px 8px; gap: 4px; }

    /* Page body */
    .page-body { padding: 14px; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .page-header h1 { font-size: 20px; }
    .page-header > div:last-child { flex-wrap: wrap; gap: 6px; }

    /* Grids collapse */
    .grid-2, .grid-3, .grid-4, .pb-grid-2 { grid-template-columns: 1fr; }
    .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }

    /* Cards */
    .card-body  { padding: 14px; }
    .card-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
    .card-title { font-size: 14px; }

    /* Settings specific */
    .card[style*="max-width"] { max-width: 100% !important; }

    /* Buttons wrap */
    .btn-group, .d-flex { flex-wrap: wrap; }

    /* DataTables */
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: left !important;
        margin-bottom: 8px;
    }
    .dataTables_wrapper .dataTables_filter input { width: 100%; }

    /* Dashboard */
    .dash-stat-grid  { grid-template-columns: repeat(2,1fr); gap: 12px; }
    .dash-main-grid  { grid-template-columns: 1fr; }
    .dash-table-grid { grid-template-columns: 1fr; }
    .dash-page-header { flex-direction: column; align-items: flex-start; }
    .dash-date-input  { width: 100%; flex-wrap: wrap; }
    .dash-filter-bar  { width: 100%; }
    .dash-mgr-banner  { flex-direction: column; align-items: flex-start; }
}

/* ══ 580px — Small tablet / large phone ════════════════════════ */
@media (max-width: 580px) {
    .topbar { padding: 0 10px; gap: 6px; }
    .topbar-title { font-size: 13px; }

    /* Stats grid: 2 columns */
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .dash-stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

    /* Inline action rows wrap */
    .d-flex, .flex-row { flex-wrap: wrap; gap: 6px; }

    /* Referral stat row */
    .ref-stat-row { grid-template-columns: 1fr 1fr !important; gap: 10px; }

    /* Postback test wrap */
    .gpt-wrap, .pt-wrap { grid-template-columns: 1fr !important; }

    /* Global PB mgmt table overflow */
    .gpb-table { font-size: 12px; }
    .gpb-table th, .gpb-table td { padding: 8px 10px; }
}

/* ══ 480px — Phone ══════════════════════════════════════════════ */
@media (max-width: 480px) {
    .page-body { padding: 10px; }
    .page-header h1 { font-size: 18px; }
    .card-body  { padding: 12px; }
    .card-header { padding: 10px 12px; }

    .btn { font-size: 13px; padding: 8px 12px; }
    .btn-sm { font-size: 11px; padding: 5px 9px; }

    .form-control { font-size: 14px; padding: 9px 12px; }
    .form-group label { font-size: 13px; }
    .form-group { margin-bottom: 14px; }

    /* Tables */
    thead th { padding: 9px 10px; font-size: 10px; }
    tbody td  { padding: 10px 10px; font-size: 12px; }

    /* Sidebar narrower */
    .sidebar { width: min(260px, 86vw); }

    /* Dashboard stats */
    .dash-stat-value { font-size: 22px; }
    .dash-kpi-card   { flex: 1 1 100%; }
    .dash-kpi-value  { font-size: 16px; }

    /* Referral full-width stat cards */
    .ref-stat-row { grid-template-columns: 1fr !important; }

    /* Settings cards */
    .card[style*="max-width"] { max-width: 100% !important; }

    /* Action buttons in tables: stack */
    td .d-flex, td [style*="display:flex"] { flex-wrap: wrap; gap: 4px; }

    /* Topbar actions: hide less important items */
    .topbar-actions > a:first-child { display: none; }
}

/* ══ 360px — Very small phones ══════════════════════════════════ */
@media (max-width: 360px) {
    .page-body { padding: 8px; }
    .btn { padding: 7px 10px; font-size: 12px; }
    .card-body { padding: 10px; }
    .dash-stat-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
    .dash-stat-value { font-size: 18px; }
    .stats-grid { grid-template-columns: 1fr; }
    .topbar-title { display: none; }
}

/* ══════════════════════════════════════════════════════════════════
   TARGETED MOBILE FIXES — Reports, Click Log, Referral, Login Logs
   ══════════════════════════════════════════════════════════════════ */

/* ── Stat cards grid: always responsive ── */
.stats-grid {
    display: grid;
    gap: 12px;
}
/* Override any inline fixed columns */
.stats-grid[style*="repeat(5"] ,
.stats-grid[style*="repeat(6"] ,
.stats-grid[style*="repeat(4"] {
    grid-template-columns: unset !important;
}

/* ── Filter form: always flex-wrap ── */
.d-flex.gap-3.align-center,
form.d-flex { flex-wrap: wrap !important; }
form .form-group.mb-0 { flex: 1 1 140px; min-width: 120px; max-width: 100%; }
form .form-group.mb-0 .form-control { width: 100%; box-sizing: border-box; }

/* ── Referral stat cards ── */
.ref-stat-row {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
    gap: 12px !important;
}
.ref-stat-card .value { font-size: 24px !important; }

/* ── Login logs: live-grid ── */
.live-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)) !important;
}
.act-summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
}
/* Unknown user avatar fallback */
.live-avatar-unknown {
    background: #6B7280 !important;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    font-size: 18px;
}

/* ── Tab bars: always scrollable ── */
[style*="display:flex"][style*="border-bottom:2px solid #E2E8F0"],
[style*="display:flex"][style*="border-bottom: 2px solid"] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    flex-wrap: nowrap !important;
}

/* ── All filter forms ── */
.act-filter-bar { flex-wrap: wrap !important; }

@media (max-width: 900px) {
    /* Reports stat grid: 3 cols */
    .stats-grid { grid-template-columns: repeat(3, 1fr) !important; }
}

@media (max-width: 640px) {
    /* Reports stat grid: 2 cols */
    .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }

    /* stat card text smaller */
    .stat-card .stat-value { font-size: 22px !important; }
    .stat-card .stat-label { font-size: 10px !important; }

    /* Live grid: 1 col on phones */
    .live-grid { grid-template-columns: 1fr !important; }

    /* Act summary: 2 cols */
    .act-summary-grid { grid-template-columns: repeat(2, 1fr) !important; }

    /* Filter form fields: full width on phone */
    form .form-group.mb-0 { flex: 1 1 100% !important; max-width: 100% !important; }

    /* Date inputs full width */
    input[type="date"].form-control { width: 100%; }

    /* Tab bar items smaller */
    [style*="border-bottom:2px solid #E2E8F0"] a,
    [style*="border-bottom: 2px solid"] a {
        padding: 8px 10px !important;
        font-size: 12px !important;
    }

    /* Referral stat row: 2 cols */
    .ref-stat-row { grid-template-columns: repeat(2, 1fr) !important; }
    .ref-stat-card .label { font-size: 10px !important; }
    .ref-stat-card .value { font-size: 20px !important; }

    /* Login logs summary: 2 cols */
    .act-sum-val { font-size: 20px; }
    .act-sum-icon { width: 38px; height: 38px; font-size: 16px; }

    /* Force all fixed-width filter inputs to auto */
    .form-control[style*="width:110px"],
    .form-control[style*="min-width:110px"],
    .form-control[style*="min-width:130px"],
    .form-control[style*="width: 110px"] {
        width: 100% !important;
        min-width: unset !important;
    }
}

@media (max-width: 400px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
    .stat-card { padding: 12px !important; }
    .stat-card .stat-value { font-size: 18px !important; }
    .ref-stat-row { grid-template-columns: 1fr 1fr !important; }
    .act-summary-grid { grid-template-columns: 1fr 1fr !important; }
}

/* ══════════════════════════════════════════════════════════════════
   COMPREHENSIVE MOBILE RESPONSIVENESS FIXES v2
   Targets all issues visible in mobile screenshots
   ══════════════════════════════════════════════════════════════════ */

/* ── 1. Topbar: prevent overflow, allow wrapping ── */
.topbar {
    flex-wrap: nowrap;
    overflow: visible;  /* must be visible so dropdown-menu (position:absolute) is not clipped */
}
/* The inner icon/balance area in affiliate topbar */
.topbar > div[style*="display:flex"] {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
}
/* Balance pill: allow shrinking */
#aff-balance-wrap {
    white-space: nowrap;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
}
/* topbar-title: allow shrinking gracefully */
.topbar-title {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── 2. Table overflow: ALL tables get horizontal scroll ── */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
table {
    min-width: 600px;
}
.dataTables_wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
/* DataTables scrolling container fix */
.dataTables_scrollBody {
    overflow-x: auto !important;
}

/* ── 3. Card overflow: ensure cards never clip content ── */
.card {
    overflow: visible;
}
.card .table-wrap {
    overflow-x: auto;
}

/* ── 4. Page header button wrapping ── */
.page-header {
    flex-wrap: wrap;
    gap: 10px;
}
.page-header > div:last-child {
    flex-wrap: wrap;
    gap: 6px;
}

/* ── 5. Offers filter: view toggle buttons stay on row ── */
#btn-list-view, #btn-grid-view {
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── 6. Conversions page tabs ── */
.conv-tabs-row {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    white-space: nowrap;
}
.conv-tabs-row::-webkit-scrollbar { display: none; }

/* ── 7. an-kpi-grid: affiliate dashboard KPI cards ── */
.an-kpi-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
}

/* ── 8. Notification dropdown: prevent off-screen ── */
#notif-dropdown {
    right: 0 !important;
    max-width: calc(100vw - 20px) !important;
    width: min(320px, calc(100vw - 20px)) !important;
}
/* On narrow phones use fixed positioning so the panel is always fully on-screen */
@media (max-width: 540px) {
    #notif-dropdown {
        position: fixed !important;
        top: 60px !important;
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        max-width: none !important;
        z-index: 99999 !important;
    }
}

/* ── Advanced Analytics 3-col grid: responsive override ── */
/* Targets the inline style="...grid-template-columns:1fr 1fr 1fr..." used in affiliate analytics */
@media (max-width: 1024px) {
    div[style*="grid-template-columns:1fr 1fr 1fr"] {
        grid-template-columns: 1fr 1fr !important;
    }
}
@media (max-width: 640px) {
    div[style*="grid-template-columns:1fr 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* ── 9. Any inline display:flex with gap: allow wrapping ── */
.card-header {
    flex-wrap: wrap;
    gap: 8px;
    min-height: auto;
}

/* ── 10. Form filter rows: full wrapping ── */
form[style*="display:flex"] {
    flex-wrap: wrap !important;
}
div[style*="display:flex"][style*="gap"] {
    flex-wrap: wrap;
}

/* ── 11. Grid-2 charts: stack on phone ── */
.grid-2 .card canvas {
    max-width: 100%;
}

/* ── 12. Table actions: wrap on small screens ── */
td .d-flex,
td [style*="display:flex"],
td [style*="display: flex"] {
    flex-wrap: wrap;
    gap: 4px;
}

/* ── 13. Min-width on fixed inputs: override ── */
input[style*="min-width"],
select[style*="min-width"] {
    min-width: min(100%, var(--original-min-width, 120px)) !important;
}

/* ══ MOBILE: 768px ══════════════════════════════════════════════ */
@media (max-width: 768px) {

    /* Topbar icons group: shrink and hide less important items */
    .topbar > div[style*="margin-right:8px"] {
        gap: 4px !important;
    }
    #news-bell-wrap { display: none; }

    /* Balance pill: compact on tablet */
    #aff-balance-wrap {
        padding: 4px 8px !important;
        font-size: 12px !important;
    }
    #aff-balance-wrap svg { display: none; }

    /* KPI grid: 3 cols on tablet */
    .an-kpi-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 10px !important;
    }
    .an-kpi-value { font-size: 20px !important; }
    .an-kpi-card  { padding: 14px 12px 12px !important; }

    /* Stats grid: 2 columns */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Offers filter: each input full width */
    .card-body form .form-group[style*="min-width"] {
        min-width: 0 !important;
        flex: 1 1 calc(50% - 6px) !important;
    }

    /* Offers view toggle: stay right */
    .card-body form > div[style*="margin-left:auto"] {
        margin-left: 0 !important;
        width: 100%;
        justify-content: flex-end;
    }

    /* Affiliate header: stack on mobile */
    .an-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 18px 20px;
    }
    .an-filters {
        width: 100%;
    }
    .an-filter-input {
        flex: 1 1 calc(50% - 5px) !important;
        min-width: 0 !important;
    }

    /* grid-2 charts: stack */
    .grid-2 {
        grid-template-columns: 1fr !important;
    }

    /* Conversion tabs: horizontal scroll */
    div[style*="border-bottom:2px solid #E2E8F0"],
    div[style*="border-bottom: 2px solid #E2E8F0"] {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        white-space: nowrap !important;
        scrollbar-width: none !important;
        display: flex !important;
        flex-wrap: nowrap !important;
    }
    div[style*="border-bottom:2px solid #E2E8F0"]::-webkit-scrollbar,
    div[style*="border-bottom: 2px solid #E2E8F0"]::-webkit-scrollbar {
        display: none;
    }

    /* Conversion tabs: keep inline */
    div[style*="border-bottom:2px solid #E2E8F0"] a,
    div[style*="border-bottom: 2px solid #E2E8F0"] a {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        padding: 8px 12px !important;
        font-size: 12px !important;
    }

    /* Offers grid view: 1 col */
    #view-grid {
        grid-template-columns: 1fr !important;
    }

    /* Admin/affiliate mode banner */
    div[style*="background:#F59E0B"] {
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px 14px !important;
    }
    div[style*="background:#F59E0B"] span,
    div[style*="background:#F59E0B"] a {
        font-size: 12px !important;
    }

    /* Tracking link cell in offers table */
    td[style*="min-width:280px"] {
        min-width: 220px !important;
    }

    /* Advertiser/Affiliate tables: all cells visible */
    .dataTables_wrapper table,
    .table-wrap table {
        min-width: 500px;
    }

    /* Stat-card value size */
    .stat-card .stat-value {
        font-size: 20px !important;
    }
}

/* ══ MOBILE: 580px ══════════════════════════════════════════════ */
@media (max-width: 580px) {

    /* Topbar: balance pill hide text, show icon only */
    #aff-balance-display {
        display: none;
    }
    #aff-balance-wrap {
        padding: 5px 7px !important;
    }
    #aff-balance-wrap svg {
        display: block !important;
    }

    /* KPI grid: 2 cols */
    .an-kpi-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    .an-kpi-value { font-size: 18px !important; }
    .an-kpi-label { font-size: 10px !important; }

    /* Stat cards: 2 cols */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    /* Page header: stack */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .page-header h1 { font-size: 18px; }
    .page-header p  { font-size: 13px; }
    .page-header > div:last-child {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    /* Buttons on page header: auto width */
    .page-header .btn {
        flex: 1 1 auto;
        text-align: center;
        min-width: 100px;
    }

    /* Affiliate analytics filter */
    .an-filter-input {
        flex: 1 1 100% !important;
    }
    .an-btn-filter {
        width: 100%;
        justify-content: center;
    }
    .an-period-tabs {
        width: 100%;
        justify-content: space-between;
    }

    /* Filter forms: all fields full width */
    .card-body form .form-group,
    .card-body form .form-group[style*="min-width"] {
        flex: 1 1 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }
    .card-body form .form-control {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    /* Filter submit buttons: full width */
    .card-body form > div[style*="display:flex"] {
        width: 100%;
    }
    .card-body form .btn-primary {
        flex: 1;
    }

    /* Offers view toggle: full width row */
    .card-body form > div[style*="margin-left:auto"] {
        margin-left: 0 !important;
        width: 100%;
        display: flex;
        justify-content: flex-end;
    }

    /* Conversion tabs scroll */
    div[style*="border-bottom:2px solid #E2E8F0"] a,
    div[style*="border-bottom: 2px solid #E2E8F0"] a {
        padding: 7px 9px !important;
        font-size: 11px !important;
        gap: 3px !important;
    }

    /* an-section-title: smaller */
    .an-section-title { font-size: 14px; }

    /* Chart canvases: constrain height */
    canvas { max-height: 220px; }

    /* Offer grid view: 1 col */
    #view-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ══ MOBILE: 480px ══════════════════════════════════════════════ */
@media (max-width: 480px) {

    /* Topbar: very compact */
    .topbar {
        height: auto !important;
        min-height: 52px;
        padding: 8px 10px !important;
        gap: 6px !important;
        flex-wrap: nowrap;
    }

    /* Hide balance entirely, show bell only */
    #aff-balance-wrap { display: none !important; }
    #chat-bell        { display: none !important; }

    /* Notification dropdown: handled by @media 540px fixed block above */

    /* User menu: avatar only */
    .user-menu span { display: none !important; }
    .user-menu > svg:last-child { display: none !important; }
    .user-menu { padding: 5px 7px !important; gap: 0 !important; }

    /* KPI value: smaller */
    .an-kpi-value  { font-size: 16px !important; }
    .an-kpi-card   { padding: 12px 10px !important; }

    /* Stats grid: 2 cols always */
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 6px !important;
    }
    .stat-card { padding: 12px 10px !important; }
    .stat-card .stat-value { font-size: 18px !important; }
    .stat-card .stat-label { font-size: 10px !important; }
    .stat-card .stat-sub   { font-size: 10px !important; }

    /* An-header: compact */
    .an-header { padding: 14px 16px; border-radius: 10px; }
    .an-title  { font-size: 18px !important; }

    /* Card body padding: compact */
    .card-body  { padding: 10px !important; }
    .card-header { padding: 10px 12px !important; }

    /* Canvas charts: max height */
    canvas { max-height: 180px !important; }

    /* Funnel bars: compact */
    .an-funnel-bar { height: 22px; }

    /* Table wrap: full scroll */
    .table-wrap, .dataTables_wrapper {
        width: 100%;
        overflow-x: auto;
    }
    table, table.dataTable {
        min-width: 480px;
    }

    /* Smaller table cells */
    thead th { padding: 8px 8px !important; font-size: 10px !important; }
    tbody td  { padding: 8px 8px !important; font-size: 12px !important; }

    /* Page body padding */
    .page-body { padding: 8px !important; }

    /* Manager banner in affiliate topbar */
    .an-mgr-banner {
        flex-direction: column !important;
        align-items: flex-start !important;
        padding: 12px 16px !important;
    }
}

/* ══ MOBILE: 360px ══════════════════════════════════════════════ */
@media (max-width: 360px) {

    .an-kpi-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 6px !important;
    }
    .an-kpi-value { font-size: 15px !important; }

    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 6px !important;
    }
    .stat-card .stat-value { font-size: 16px !important; }

    .page-body { padding: 6px !important; }
    .card-body  { padding: 8px !important; }

    table, table.dataTable { min-width: 380px; }

    /* Conversion tab: tiny */
    div[style*="border-bottom:2px solid #E2E8F0"] a,
    div[style*="border-bottom: 2px solid #E2E8F0"] a {
        padding: 6px 7px !important;
        font-size: 10px !important;
    }
}

/* ══ UNIVERSAL OVERFLOW PREVENTION ═════════════════════════════ */

/* Prevent any element from causing horizontal page scroll */
.page-body > * {
    max-width: 100%;
}

/* All inline styles with fixed min-widths: override on small screens */
@media (max-width: 480px) {
    [style*="min-width:280px"],
    [style*="min-width: 280px"],
    [style*="min-width:320px"],
    [style*="min-width:300px"] {
        min-width: 0 !important;
        width: 100% !important;
    }
    [style*="width:320px"],
    [style*="width: 320px"],
    [style*="width:300px"] {
        width: 100% !important;
    }
}

/* ══ DATATABLES MOBILE IMPROVEMENTS ════════════════════════════ */
div.dataTables_wrapper div.dataTables_filter {
    text-align: left;
}
@media (max-width: 580px) {
    div.dataTables_wrapper div.dataTables_length,
    div.dataTables_wrapper div.dataTables_filter,
    div.dataTables_wrapper div.dataTables_info,
    div.dataTables_wrapper div.dataTables_paginate {
        float: none !important;
        text-align: left !important;
        padding: 6px 0 !important;
        display: block !important;
        width: 100%;
    }
    div.dataTables_wrapper div.dataTables_filter input {
        width: 100% !important;
        margin-left: 0 !important;
        display: block;
    }
    div.dataTables_wrapper div.dataTables_paginate .paginate_button {
        padding: 4px 8px !important;
        font-size: 12px !important;
    }
}

/* ══ AFFILIATE TOPBAR ICON ROW — FLEXIBLE ══════════════════════ */
/* The div containing balance + news + notifications + chat */
.topbar > div[style*="align-items:center"][style*="gap:8px"],
.topbar > div[style*="align-items: center"][style*="gap: 8px"] {
    flex-shrink: 1;
    overflow: visible;
}

/* ══ OFFER GRID & IN-HOUSE OFFER GRID — EQUAL COLUMNS, NO OVERFLOW ═ */
/*
 * Safari fix: auto-fill keeps empty ghost columns which shrink real cards.
 * auto-fit collapses empty columns so filled cards expand to fill the row.
 * The inline styles on #view-grid / #ih-view-grid already use auto-fit.
 * This block reinforces that and adds -webkit- prefix for older Safari.
 */
#view-grid,
#ih-view-grid {
    display: -webkit-grid;
    display: grid;
    -webkit-grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    align-items: start;
    /* Prevent the grid itself from overflowing its container in Safari */
    width: 100%;
    box-sizing: border-box;
}

/* Grid items: force containment so no child inflates the column */
#view-grid > .card,
#ih-view-grid > .card {
    min-width: 0;
    max-width: 100%;
    width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

/* Images inside offer cards: always fill card, never overflow */
#view-grid .card img,
#ih-view-grid .card img {
    max-width: 100%;
    width: 100%;
    display: block;
    height: auto;
}

/* iframes: clamp to card width in all browsers including Safari */
#view-grid .card iframe,
#ih-view-grid .card iframe {
    max-width: 100% !important;
    width: 100% !important;
    display: block;
}

/* Responsive: single column below 720px */
@media (max-width: 720px) {
    #view-grid,
    #ih-view-grid {
        -webkit-grid-template-columns: 1fr !important;
        grid-template-columns: 1fr !important;
    }
}

/* ══ SAFARI GRID ITEM CONTAINMENT (global) ══════════════════════ */
/*
 * Any CSS grid that uses repeat(auto-fit/fill, minmax(..., 1fr)) must have
 * its items contained to prevent intrinsic size leaking the column width.
 * Target all direct .card children of any grid-based layout container.
 */
.grid-2 > .card,
.grid-3 > .card,
.grid-4 > .card {
    min-width: 0;
    max-width: 100%;
}

