:root {
    --sidebar-bg: #0D0D59;
    --sidebar-hover: #1a1a7a;
    --bg-light: #f4f7fe;
    --card-bg: #ffffff;
    --text-main: #2b3674;
    --text-secondary: #a3aed0;
    --accent: #4318ff;
    --success: #A8CF45;
    --pending: #ffb547;
    --failed: #ee5d50;
    --border: #e9edf7;
    --velcro-green: #A8CF45;
    --velcro-navy: #0D0D59;
    --input-bg: #ffffff;
    --code-bg: #f1f5f9;
    --primary-link: #0D0D59;
}

.dark {
    --sidebar-bg: #08083d;
    --sidebar-hover: #12125a;
    --bg-light: #020617;
    --card-bg: #0f172a;
    --text-main: #e2e8f0;
    --text-secondary: #94a3b8;
    --accent: #6366f1;
    --border: #334155;
    --velcro-navy: #818cf8;
    --input-bg: #1e293b;
    --code-bg: #1e293b;
    --primary-link: #818cf8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

body {
    background-color: var(--bg-light);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Login Screen --- */
#auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-light);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: 0.5s ease;
}

.auth-card {
    background: var(--card-bg);
    padding: 50px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.05);
    width: 100%;
    max-width: 450px;
    text-align: center;
}

.auth-card img {
    width: 120px;
    margin-bottom: 30px;
}

.auth-card h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.auth-card p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 30px;
}

input {
    width: 100%;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 14px;
    margin-bottom: 20px;
    outline: none;
    transition: 0.3s;
}

input:focus {
    border-color: var(--sidebar-bg);
}

.btn-secondary {
    width: 100%;
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 14px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
}

.btn-secondary:hover {
    border-color: var(--velcro-navy);
    background: var(--bg-light);
}

.btn-primary {
    width: 100%;
    background: var(--success);
    color: #0D0D59;
    border: none;
    padding: 16px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.3s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(168, 207, 69, 0.4);
}

/* --- Main Layout --- */
aside {
    width: 290px;
    background: var(--sidebar-bg);
    padding: 40px 20px;
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 1001;
    transition: transform 0.3s ease;
}

.logo-box {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 60px;
    padding-left: 15px;
}

.mobile-header {
    display: none;
    background: var(--sidebar-bg);
    color: white;
    padding: 15px 20px;
    position: sticky;
    top: 0;
    z-index: 1000;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
}

.sidebar-overlay.active {
    display: block;
}

.hamburger {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
}

nav ul {
    list-style: none;
}

nav li {
    padding: 15px 18px;
    border-radius: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 15px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
    transition: 0.3s;
}

nav li i {
    width: 20px;
    height: 20px;
}

nav li:hover {
    color: white;
    background: var(--sidebar-hover);
}

nav li.active {
    color: white;
    background: rgba(255, 255, 255, 0.15);
}

main {
    flex-grow: 1;
    margin-left: 290px;
    padding: 40px;
    position: relative;
}

.view-content {
    display: none;
}

.view-content.active {
    display: block;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
}

.header-title h1 {
    font-size: 34px;
    font-weight: 700;
    margin-bottom: 5px;
}

.header-title p {
    color: var(--text-secondary);
    font-size: 14px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.refresh-btn {
    background: white;
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: 12px;
    cursor: pointer;
    color: var(--text-main);
    transition: 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.refresh-btn:hover {
    background: var(--bg-light);
}

.refresh-btn.spinning i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.spinning {
    animation: spin 1s linear infinite;
}

/* --- Stats Cards --- */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: white;
    padding: 24px;
    border-radius: 20px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 15px;
}

.stat-icon {
    width: 50px;
    height: 50px;
    background: #f4f7fe;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sidebar-bg);
    flex-shrink: 0;
}

.stat-info h4 {
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 3px;
}

.stat-info span {
    font-size: 24px;
    font-weight: 700;
}

/* --- Tables --- */
.table-card {
    background: white;
    border-radius: 20px;
    border: 1px solid var(--border);
    padding: 30px;
    animation: fadeIn 0.4s ease;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 700px;
}

th {
    text-align: left;
    border-bottom: 1px solid var(--border);
    padding: 0 10px 15px 10px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
}

td {
    padding: 18px 10px;
    border-bottom: 1px solid #f8f9fc;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}
tbody tr:hover {
    background: #f8f9fc;
    cursor: pointer;
}

.user-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 36px;
    height: 36px;
    background: var(--bg-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sidebar-bg);
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}

.status-pill {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.completed { background: rgba(168, 207, 69, 0.16); color: #5f7d17; }
.awaiting_deposit, .pending, .initiated { background: #fffbeb; color: #b45309; }
.processing, .received, .verified, .detected, .confirmed { background: #f0f9ff; color: #0369a1; }
.failed { background: #fef2f2; color: #dc2626; }
.cancelled { background: #f3f4f6; color: #4b5563; }
.expired { background: #fff7ed; color: #c2410c; }
.approved { background: rgba(168, 207, 69, 0.16); color: #5f7d17; }
.sending { background: #f0f9ff; color: #0369a1; }
.sent { background: rgba(168, 207, 69, 0.16); color: #5f7d17; }
.camp-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.camp-form input, .camp-form textarea { width: 100%; margin-bottom: 14px; padding: 11px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--input-bg); color: var(--text-main); font: inherit; font-size: 14px; }
.camp-form textarea { resize: vertical; line-height: 1.6; }
.camp-label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; }
.camp-label span { text-transform: none; font-weight: 400; }
.camp-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.camp-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 4px; }
.camp-actions .btn-secondary, .camp-actions .btn-primary { width: auto; padding: 11px 18px; }
.camp-test { display: flex; gap: 8px; flex: 1 1 260px; }
.camp-test input { margin-bottom: 0 !important; flex: 1; min-width: 0; }
.camp-note { margin-top: 12px; font-size: 12px; color: var(--text-secondary); }
#camp-preview-frame { display: none; width: 100%; height: 720px; border: 1px solid var(--border); border-radius: 14px; background: #f3f4f7; }
@media (max-width: 1100px) { .camp-grid { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .camp-row { grid-template-columns: 1fr; } #camp-preview-frame { height: 560px; } }
.rejected { background: #fef2f2; color: #dc2626; }
/* HostFi deposits */
.review, .payout_failed { background: #fef2f2; color: #dc2626; }
.paid { background: rgba(168, 207, 69, 0.16); color: #5f7d17; }
.swapping, .swapped, .paying, .payout_pending, .swap_pending { background: #f0f9ff; color: #0369a1; }
.payout_uncertain { background: #fffbeb; color: #b45309; }
.resolved { background: #f3f4f6; color: #4b5563; }
.hostfi-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.hostfi-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 10px 12px; border-radius: 10px; background: var(--bg-light); border: 1px solid var(--border); }
.hostfi-toggle input { width: 18px; height: 18px; accent-color: var(--success); cursor: pointer; margin: 0; }
.hostfi-toggle-title { font-size: 13px; font-weight: 600; color: var(--text-main); }
.hostfi-toggle-sub { font-size: 11px; color: var(--text-secondary); }
.hostfi-inputs { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.hostfi-balances { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.hostfi-balance { padding: 12px 14px; border-radius: 12px; background: var(--bg-light); border: 1px solid var(--border); }
.hostfi-balance-code { font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; }
.hostfi-balance-value { margin-top: 4px; font-size: 16px; font-weight: 700; color: var(--text-main); word-break: break-all; }
.hostfi-balance-held { margin-top: 2px; font-size: 11px; font-weight: 600; color: var(--warning, #b45309); }
/* Status notes wrap under the pill instead of running under the action buttons. */
.hostfi-status-cell { white-space: normal; min-width: 220px; max-width: 340px; }
.hostfi-note { margin-top: 6px; font-size: 11px; line-height: 1.45; color: var(--text-secondary); white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; cursor: help; }
.hostfi-action-cell { width: 1%; }
.hostfi-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; min-width: 128px; }
.hostfi-actions button { width: 100%; padding: 8px 14px; font-size: 12px; white-space: nowrap; }
@media (max-width: 1100px) { .hostfi-grid { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .hostfi-inputs { grid-template-columns: 1fr; } }
/* Coins & providers */
.coins-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.coins-toolbar input { flex: 1; margin-bottom: 0; }
.coins-toolbar .btn-primary { width: auto; padding: 10px 18px; white-space: nowrap; }
.coins-note { font-size: 12px; color: var(--text-secondary); margin-bottom: 12px; }
.coins-warning { font-size: 12px; color: #b45309; background: #fffbeb; border: 1px solid #fde68a; padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; }
.route-toggle { width: 18px; height: 18px; accent-color: var(--success); cursor: pointer; margin: 0; }
.route-cell.changed { box-shadow: inset 0 0 0 2px #fbbf24; border-radius: 6px; }
.route-none { color: var(--text-secondary); }
.coin-cell { font-weight: 700; color: var(--text-main); }
.sending, .send_pending, .sent { background: #f0f9ff; color: #0369a1; }
.sent { background: rgba(168, 207, 69, 0.16); color: #5f7d17; }
.send_failed { background: #fef2f2; color: #dc2626; }
.send_uncertain { background: #fffbeb; color: #b45309; }
/* Merchant statuses */
.status-pill.approved { background: rgba(168, 207, 69, 0.16); color: #5f7d17; }
.status-pill.rejected, .status-pill.suspended { background: #fef2f2; color: #dc2626; }
.status-pill.draft { background: #f3f4f6; color: #4b5563; }
.ref-fee-input { width: 72px !important; padding: 6px 8px !important; margin: 0 !important; font-size: 13px !important; }

.btn-view {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: white;
    cursor: pointer;
    font-size: 12px;
    transition: 0.2s;
}

.btn-view:hover {
    background: var(--bg-light);
    border-color: var(--success);
}

/* --- User Detail Section --- */
.user-header {
    display: flex;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 30px;
}

.user-profile-lg {
    width: 80px;
    height: 80px;
    background: var(--bg-light);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: var(--sidebar-bg);
}

.user-details-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.detail-mini-card {
    background: #f8f9fc;
    padding: 20px;
    border-radius: 16px;
    text-align: center;
}

.detail-mini-card b {
    display: block;
    font-size: 20px;
    margin-bottom: 4px;
}

.detail-mini-card span {
    color: var(--text-secondary);
    font-size: 12px;
}

/* --- Modal --- */
.tx-modal-content {
    background: white;
    width: 500px;
    max-width: 90%;
    padding: 30px;
    border-radius: 20px;
    position: relative;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.tx-modal-info {
    background: var(--bg-light);
    padding: 15px;
    border-radius: 12px;
    margin: 20px 0;
}

.tx-modal-info > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.tx-modal-info > div:last-child {
    margin-bottom: 0;
}

.tx-modal-info > div span:first-child {
    color: var(--text-secondary);
    font-size: 13px;
}

#modal-amount {
    font-size: 16px;
}

.tx-modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* --- Hidden Utils --- */
.hidden { display: none !important; }

/* --- Responsive: Tablet & Mobile --- */
@media (max-width: 1024px) {
    aside { transform: translateX(-100%); z-index: 2000; }
    aside.active { transform: translateX(0); box-shadow: 5px 0 25px rgba(0,0,0,0.2); }
    main { margin-left: 0; padding: 20px 16px; }
    .mobile-header { display: flex; }
    .stats-row { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .stat-card { padding: 16px; }
    .stat-info span { font-size: 20px; }
    .header-title h1 { font-size: 22px; }
    .table-card { padding: 16px; }
    .user-details-stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .hide-mobile { display: none !important; }
    .table-card { overflow-x: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
    table { min-width: 600px; }
    td { padding: 12px 8px; font-size: 13px; }
    th { padding: 12px 8px; font-size: 11px; }
    .user-details-stats { grid-template-columns: 1fr; }
    .tx-modal-content {
        padding: 20px;
        max-width: 95%;
        border-radius: 16px;
    }
    .tx-modal-info {
        padding: 12px;
        margin: 16px 0;
    }
    .tx-modal-info > div {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        margin-bottom: 12px;
    }
    .tx-modal-info > div:last-child {
        margin-bottom: 0;
    }
    .tx-modal-grid {
        grid-template-columns: 1fr;
    }
    code {
        word-break: break-all;
        white-space: pre-wrap;
    }
    /* PAJ Session mobile fixes */
    #paj-session-status {
        padding: 14px 12px;
    }
    #paj-status-icon {
        width: 40px;
        height: 40px;
    }
    #paj-email-input + div,
    #paj-email-input {
        min-width: 0;
    }
    #paj-otp-section {
        padding: 14px 12px;
    }
    #paj-otp-input {
        font-size: 20px;
        letter-spacing: 6px;
        min-height: 52px;
        padding: 10px 8px;
        -webkit-appearance: none;
        appearance: none;
    }
    #paj-verify-btn {
        min-height: 52px;
        padding: 0 16px;
        font-size: 14px;
    }
    #paj-initiate-btn {
        min-height: 52px;
        font-size: 14px;
    }
    .paj-email-row {
        flex-direction: column;
    }
    .paj-email-row button {
        width: 100%;
    }
    .paj-otp-row {
        flex-direction: column;
        align-items: stretch;
    }
    .paj-otp-row input,
    .paj-otp-row button {
        width: 100%;
    }
    /* Modal mobile fixes */
    #tx-modal {
        align-items: flex-start !important;
        padding: 12px !important;
    }
    .tx-modal-content {
        max-width: 100%;
        padding: 20px;
        border-radius: 16px;
    }
    #modal-hash-input {
        font-size: 16px !important;
        min-height: 48px;
        padding: 12px;
    }
    .modal-btn-row {
        flex-direction: column !important;
    }
    .modal-btn-row button {
        width: 100%;
        min-height: 48px;
        font-size: 14px !important;
    }
    /* Cost calculator mobile */
    .cost-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .cost-input {
        width: 100%;
        text-align: left;
        font-size: 16px;
    }
    /* Filter inputs zoom fix */
    #filter-search,
    #filter-type,
    #filter-status,
    #filter-channel,
    #filter-date-from,
    #filter-date-to {
        font-size: 16px;
    }
    /* Settings inputs zoom fix */
    #fee-input,
    #paj-fee-input,
    #paj-margin-input,
    #buy-max-input,
    #sell-min-input,
    #sell-max-input,
    #paj-email-input {
        font-size: 16px;
        min-height: 48px;
    }
}

@media (max-width: 480px) {
    .stats-row { grid-template-columns: 1fr; gap: 10px; }
    .stat-card { padding: 14px; gap: 10px; }
    .stat-icon { width: 40px; height: 40px; }
    .stat-info h4 { font-size: 11px; }
    .stat-info span { font-size: 16px; }
    .auth-card { padding: 30px 20px; margin: 0 16px; }
    .user-details-stats { grid-template-columns: 1fr; }
    header { margin-bottom: 20px; }
    .header-title h1 { font-size: 20px; }
}

/* ─── Dark Mode Overrides ─── */
.dark body {
    background-color: var(--bg-light);
    color: var(--text-main);
}
.dark #auth-overlay {
    background: var(--bg-light);
}
.dark .auth-card {
    background: var(--card-bg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}
.dark input,
.dark select {
    background: var(--card-bg);
    color: var(--text-main);
    border-color: var(--border);
}
.dark .stat-card,
.dark .table-card,
.dark .tx-modal-content {
    background: var(--card-bg);
}
.dark .stat-icon {
    background: #1e293b;
    color: var(--text-main);
}
.dark .refresh-btn {
    background: var(--card-bg);
    color: var(--text-main);
    border-color: var(--border);
}
.dark .refresh-btn:hover {
    background: #1e293b;
}
.dark td {
    border-bottom-color: #1e293b;
}
.dark tbody tr:hover {
    background: #1e293b;
}
.dark .detail-mini-card {
    background: #1e293b;
}
.dark .btn-view {
    background: var(--card-bg);
    color: var(--text-main);
}
.dark .btn-view:hover {
    background: #1e293b;
}
.dark .completed { background: rgba(168, 207, 69, 0.15); color: #c4e860; }
.dark .awaiting_deposit, .dark .pending, .dark .initiated { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.dark .processing, .dark .received, .dark .verified, .dark .detected, .dark .confirmed { background: rgba(14, 165, 233, 0.15); color: #7dd3fc; }
.dark .failed { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.dark .cancelled { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; }
.dark .expired { background: rgba(249, 115, 22, 0.15); color: #fdba74; }
.dark .approved { background: rgba(168, 207, 69, 0.15); color: #c4e860; }
.dark .sending { background: rgba(14, 165, 233, 0.15); color: #7dd3fc; }
.dark .sent { background: rgba(168, 207, 69, 0.15); color: #c4e860; }
.dark .rejected { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.dark .user-profile-lg {
    background: #1e293b;
    color: var(--text-main);
}
.dark .avatar {
    background: #1e293b;
    color: var(--text-main);
}
.dark #paj-message {
    background: #064e3b !important;
    color: #34d399 !important;
    border-color: #065f46 !important;
}
.dark #paj-otp-section {
    background: linear-gradient(135deg, #451a03 0%, #78350f 100%) !important;
    border-color: #92400e !important;
}
.dark #paj-otp-section span,
.dark #paj-otp-section p {
    color: #fbbf24 !important;
}
.dark #paj-status-icon {
    background: #334155 !important;
}
.dark #paj-status-icon i {
    color: #94a3b8 !important;
}
.dark #paj-session-status {
    background: #1e293b !important;
    border-color: #334155 !important;
}
.dark .sidebar-overlay {
    background: rgba(0, 0, 0, 0.7);
}
.dark-mode-toggle {
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.8);
    border: none;
    padding: 10px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.3s;
    margin-top: auto;
    margin-bottom: 16px;
    width: 100%;
}
.dark-mode-toggle:hover {
    background: rgba(255,255,255,0.2);
}

/* --- Expanded Stats --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}
.stats-grid-2 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 40px;
}
.stat-card-sm {
    background: white;
    padding: 20px;
    border-radius: 16px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}
.stat-icon-sm {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon-sm.green { background: rgba(168, 207, 69, 0.15); color: #5a7a1a; }
.stat-icon-sm.blue { background: rgba(67, 24, 255, 0.08); color: var(--accent); }
.stat-icon-sm.amber { background: rgba(245, 158, 11, 0.12); color: #b45309; }
.stat-icon-sm.red { background: rgba(238, 93, 80, 0.1); color: var(--failed); }
.stat-icon-sm.purple { background: rgba(124, 58, 237, 0.1); color: #7c3aed; }
.stat-icon-sm.teal { background: rgba(20, 184, 166, 0.1); color: #0f766e; }
.stat-info-sm h4 {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 2px;
    font-weight: 600;
}
.stat-info-sm span {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-main);
}
.stat-info-sm .stat-sub {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* --- Analytics Page --- */
.analytics-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
.analytics-card {
    background: white;
    border-radius: 20px;
    border: 1px solid var(--border);
    padding: 28px;
}
.analytics-card h3 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-main);
}
.cost-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.cost-row:last-child { border-bottom: none; }
.cost-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-main);
}
.cost-desc {
    font-size: 12px;
    color: var(--text-secondary);
}
.cost-input {
    width: 140px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    text-align: right;
    margin-bottom: 0;
}
.profit-box {
    background: linear-gradient(135deg, var(--velcro-navy) 0%, #1a1a7a 100%);
    color: white;
    border-radius: 16px;
    padding: 24px;
    margin-top: 20px;
}
.profit-box h4 {
    font-size: 12px;
    text-transform: uppercase;
    opacity: 0.7;
    margin-bottom: 8px;
    font-weight: 600;
}
.profit-box .profit-value {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 4px;
}
.profit-box .profit-margin {
    font-size: 14px;
    opacity: 0.8;
}

/* Progress bars */
.progress-bar-bg {
    background: var(--bg-light);
    border-radius: 8px;
    height: 10px;
    overflow: hidden;
    margin-top: 8px;
}
.progress-bar-fill {
    height: 100%;
    border-radius: 8px;
    transition: width 0.6s ease;
}
.breakdown-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.breakdown-row .label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
}
.breakdown-row .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}
.breakdown-row .value {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
}

/* Logo in sidebar */
.logo-box img {
    height: 32px;
    width: auto;
}

/* Dark mode overrides for new elements */
.dark .stat-card-sm,
.dark .analytics-card {
    background: var(--card-bg);
    border-color: var(--border);
}
.dark .stat-info-sm span {
    color: var(--text-main);
}
.dark .cost-input {
    background: #1e293b;
    border-color: var(--border);
    color: var(--text-main);
}
.dark .progress-bar-bg {
    background: #1e293b;
}
.dark .settings-grid .table-card > div[style*="background: var(--bg-light)"] {
    background: #1e293b !important;
    border-color: var(--border) !important;
}

code, pre {
    word-break: break-all;
    white-space: pre-wrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.api-tools-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.api-tab {
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.api-tabs-scroll {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.api-tabs-scroll::-webkit-scrollbar {
    height: 4px;
}
.api-tabs-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

@media (max-width: 1100px) {
    .stats-grid, .stats-grid-2, .analytics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .settings-grid, .api-tools-grid {
        grid-template-columns: 1fr !important;
    }
}
@media (max-width: 640px) {
    .stats-grid, .stats-grid-2, .analytics-grid, .settings-grid, .api-tools-grid {
        grid-template-columns: 1fr !important;
    }
    header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 14px !important;
        margin-bottom: 22px !important;
    }
    .header-actions {
        width: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 10px !important;
    }
    .header-actions .btn-primary {
        flex: 1 !important;
    }
    input, select, textarea, .cost-input {
        font-size: 16px !important;
    }
    .filters-grid {
        grid-template-columns: 1fr 1fr !important;
    }
}
@media (max-width: 480px) {
    .filters-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ─── Phones ─── */
@media (max-width: 640px) {
    /* Title and its actions share a row when they fit (refresh no longer floats alone). */
    header {
        flex-direction: row !important;
        flex-wrap: wrap;
        align-items: center !important;
        justify-content: space-between;
    }
    header .header-title { flex: 1 1 200px; min-width: 0; }
    .header-actions { width: auto !important; }

    /* Tables become stacked cards: every column visible, labelled from data-label. */
    .table-card { overflow-x: visible; padding: 12px; }
    .table-card table { min-width: 0; margin-top: 0 !important; }
    .table-card thead { display: none; }
    .table-card table, .table-card tbody, .table-card tr { display: block; width: 100%; }
    .table-card tr {
        border: 1px solid var(--border);
        border-radius: 14px;
        padding: 2px 14px;
        margin-bottom: 10px;
        background: var(--card-bg);
    }
    .table-card td {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        column-gap: 12px;
        align-items: center;
        justify-items: end;
        padding: 9px 0 !important;
        border: 0 !important;
        text-align: right;
        max-width: none !important;
        white-space: normal !important;
        overflow: visible !important;
        word-break: break-word;
    }
    .table-card td + td { border-top: 1px dashed var(--border) !important; }
    .table-card td > * { grid-column: 2; }
    .table-card td::before {
        content: attr(data-label);
        grid-column: 1;
        grid-row: 1 / span 6;
        justify-self: start;
        text-align: left;
        font-size: 11px;
        font-weight: 600;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: var(--text-secondary);
    }
    /* First column (user / reference) is the card's heading. */
    .table-card td:first-child,
    .table-card td[colspan] { grid-template-columns: minmax(0, 1fr); }
    .table-card td:first-child > * { grid-column: 1; }
    .table-card td:first-child { justify-items: start; text-align: left; padding-top: 12px !important; }
    .table-card td:first-child::before,
    .table-card td[colspan]::before { display: none; }
    .table-card td[colspan] { justify-items: center; text-align: center; }
    .table-card td[colspan] > * { grid-column: 1; }

    /* Transaction details: bottom sheet. */
    #tx-modal { align-items: flex-end !important; padding: 0 !important; }
    .tx-modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 92dvh;
        border-radius: 24px 24px 0 0 !important;
        padding: 22px 18px calc(22px + env(safe-area-inset-bottom)) !important;
    }
}
@media (max-width: 480px) {
    /* Stats: two compact columns instead of eight full-width cards. */
    .stats-row, .stats-grid, .stats-grid-2 { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
    .stat-card { flex-direction: column; align-items: flex-start; padding: 14px; gap: 10px; }
    .stat-icon { width: 36px; height: 36px; border-radius: 10px; }
    .stat-icon svg { width: 18px; height: 18px; }
    .stat-info span { font-size: 16px; line-height: 1.25; word-break: break-word; }
}

/* ─── Phones: tab bar, compact order cards, folded filters ─── */
.phone-tabs, .filters-toggle { display: none; }
@media (max-width: 1024px) {
    main { padding-bottom: calc(88px + env(safe-area-inset-bottom)) !important; }
    aside { overflow-y: auto; }
    .phone-tabs {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 1000;
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
        background: var(--card-bg);
        border-top: 1px solid var(--border);
        box-shadow: 0 -6px 20px rgba(13, 13, 89, 0.06);
    }
    .phone-tabs button {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        padding: 6px 2px;
        background: none;
        border: 0;
        border-radius: 10px;
        cursor: pointer;
        color: var(--text-secondary);
        font-family: inherit;
        font-size: 10.5px;
        font-weight: 600;
    }
    .phone-tabs svg { width: 20px; height: 20px; }
    .phone-tabs button.is-on { color: var(--velcro-navy); background: rgba(13, 13, 89, 0.06); }
    .dark .phone-tabs button.is-on { color: var(--text-main); background: rgba(255, 255, 255, 0.08); }
}
@media (max-width: 640px) {
    /* Action rows: buttons full size, label beside them. */
    .table-card td.hostfi-action-cell { width: 100%; }
    .table-card .hostfi-actions { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
    .table-card .hostfi-actions button { width: auto; min-height: 38px; }

    /* Dashboard: small tiles so recent activity is near the top. */
    .stats-row, .stats-grid, .stats-grid-2 { gap: 8px !important; margin-bottom: 8px !important; }
    .stat-card, .stat-card-sm { display: block !important; position: relative; padding: 12px !important; min-height: 0 !important; }
    .stat-icon, .stat-icon-sm { position: absolute; top: 10px; right: 10px; width: 26px !important; height: 26px !important; border-radius: 8px !important; margin: 0 !important; }
    .stat-icon svg, .stat-icon-sm svg { width: 14px !important; height: 14px !important; }
    .stat-info h4, .stat-info-sm h4 { font-size: 10.5px !important; line-height: 1.25; padding-right: 30px; margin-bottom: 4px; }
    .stat-info span, .stat-info-sm span { font-size: 15px !important; line-height: 1.25; }
    .stat-info-sm .stat-sub { font-size: 10.5px !important; margin-top: 2px; }

    /* Orders: one compact card per order; tap it for the details. */
    #all-tx-body tr, #tx-summary-body tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 6px 10px;
        align-items: center;
        padding: 12px 14px;
        margin-bottom: 8px;
    }
    #all-tx-body td, #tx-summary-body td {
        display: block;
        padding: 0 !important;
        border: 0 !important;
        text-align: left;
    }
    #all-tx-body td::before, #tx-summary-body td::before { display: none; }
    #all-tx-body td[data-label="User"], #tx-summary-body td[data-label="User"] { grid-column: 1; grid-row: 1; }
    #all-tx-body td[data-label="Amount"], #tx-summary-body td[data-label="Amount"] { grid-column: 2; grid-row: 1; text-align: right; }
    #all-tx-body td[data-label="Type"], #tx-summary-body td[data-label="Type"] { grid-column: 1; grid-row: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; }
    #all-tx-body td[data-label="Type"] > div, #tx-summary-body td[data-label="Type"] > div { margin-top: 0 !important; }
    #all-tx-body td[data-label="Status"], #tx-summary-body td[data-label="Status"] { grid-column: 2; grid-row: 2; text-align: right; }
    #all-tx-body td[data-label="Channel"], #tx-summary-body td[data-label="Channel"] { grid-column: 1; grid-row: 3; }
    #all-tx-body td[data-label="Date"], #tx-summary-body td[data-label="Time"] { display: block !important; grid-column: 2; grid-row: 3; text-align: right; font-size: 11px; color: var(--text-secondary); }
    #all-tx-body td[data-label="Action"] { display: none; }
    #all-tx-body .avatar, #tx-summary-body .avatar { width: 30px; height: 30px; font-size: 11px; flex-shrink: 0; }
    #all-tx-body .user-cell b, #tx-summary-body .user-cell b { max-width: 130px !important; }

    /* Filters: search stays, the rest folds behind a button. */
    #tx-filters { padding: 12px !important; margin-bottom: 12px !important; }
    #tx-filters .filters-grid { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
    #tx-filters .filters-grid > div:first-child { grid-column: 1 / -1; }
    #tx-filters:not(.is-open) .filters-grid > div:not(:first-child) { display: none; }
    #tx-filters:not(.is-open) .filters-foot > div { display: none !important; }
    #tx-filters .filters-foot { margin-top: 6px !important; }
    .filters-toggle {
        display: block;
        width: 100%;
        margin-top: 8px;
        padding: 9px;
        background: none;
        border: 1px solid var(--border);
        border-radius: 10px;
        color: var(--text-main);
        font-family: inherit;
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
    }

    /* Order details: room to type an email next to the button. */
    #modal-email-input { min-width: 0; flex: 1 1 0 !important; }
    #modal-send-receipt-btn { width: auto !important; flex: 0 0 auto !important; }
}
