/* Ahora TV — Admin Dashboard styles
   Paleta de la app Android: azul #4338CA → purple #7C3AED → magenta #EC4899 */

:root {
    --brand-blue: #4338CA;
    --brand-purple: #7C3AED;
    --brand-purple-light: #A78BFA;
    --brand-magenta: #EC4899;
    --brand-cyan: #06B6D4;

    --bg: #06060A;
    --bg-end: #0D0D14;
    --surface: #111119;
    --surface-v: #1A1A28;
    --surface-el: #222236;
    --glass-border: rgba(255, 255, 255, 0.07);
    --card-bg: #14141F;

    --t1: #EAECF0;
    --t2: #8B95A8;
    --t3: #7B8BA3;

    --err: #EF4444;
    --ok: #10B981;
    --warn: #FBBF24;
    --live: #FF2D55;

    --grad: linear-gradient(135deg, var(--brand-blue), var(--brand-purple), var(--brand-magenta));
    --grad-h: linear-gradient(90deg, var(--brand-blue), var(--brand-purple), var(--brand-magenta));
}

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

html, body {
    background: var(--bg);
    color: var(--t1);
    font-family: "Inter", system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a {
    color: var(--brand-purple-light);
    text-decoration: none;
}

a:hover { text-decoration: underline; }

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

input, select, textarea {
    font-family: inherit;
    background: var(--surface-v);
    color: var(--t1);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--brand-purple-light);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--grad);
    color: white;
}

.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
    background: var(--surface-v);
    color: var(--t1);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover { border-color: var(--brand-purple); }

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--err);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.btn-ok {
    background: rgba(16, 185, 129, 0.15);
    color: var(--ok);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.btn-ok:hover { background: rgba(16, 185, 129, 0.25); }

.btn-warn {
    background: rgba(251, 191, 36, 0.15);
    color: var(--warn);
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 20px;
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-ok { background: rgba(16, 185, 129, 0.15); color: var(--ok); }
.badge-err { background: rgba(239, 68, 68, 0.15); color: var(--err); }
.badge-warn { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge-info { background: rgba(124, 58, 237, 0.15); color: var(--brand-purple-light); }

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background:
        radial-gradient(1200px 600px at 10% 10%, rgba(67,56,202,0.15), transparent),
        radial-gradient(800px 400px at 90% 90%, rgba(236,72,153,0.1), transparent),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.login-title {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 6px;
    background: var(--grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-subtitle { color: var(--t2); font-size: 14px; margin-bottom: 28px; }

.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--t2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.form-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--err);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* App layout */
.app-wrap {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--glass-border);
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-brand {
    padding: 8px 24px 24px;
    font-size: 16px;
    font-weight: 800;
    background: var(--grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    color: var(--t2);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}

.nav-item:hover { color: var(--t1); background: var(--surface-v); }

.nav-item.active {
    color: var(--t1);
    background: var(--surface-v);
    border-left-color: var(--brand-purple);
}

.main {
    padding: 24px 32px;
    overflow-x: auto;
}

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

.topbar h1 { font-size: 22px; font-weight: 700; }

.credit-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--surface-v);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    font-size: 13px;
}

.credit-pill .value { color: var(--brand-purple-light); font-weight: 700; }

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    background: var(--surface-v);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    font-size: 13px;
}

.user-chip .role {
    font-size: 10px;
    background: var(--brand-purple);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
}

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

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 18px 20px;
}

.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--t3);
    margin-bottom: 6px;
}

.stat-value {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.3px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--t3);
    border-bottom: 1px solid var(--glass-border);
}

tbody td {
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

tbody tr:hover { background: rgba(124, 58, 237, 0.04); }

.table-wrap {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    overflow: hidden;
}

.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.toolbar .spacer { flex: 1; }

.toolbar input[type="search"] { width: 260px; }

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 28px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 18px; }

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 200;
}

.toast {
    background: var(--card-bg);
    border-left: 3px solid var(--brand-purple);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    min-width: 260px;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: slide-in 0.2s ease-out;
}

.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }

@keyframes slide-in {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.hidden { display: none !important; }
.text-muted { color: var(--t2); }
.text-small { font-size: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

.empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--t2);
    font-size: 14px;
}

.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--brand-purple);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Toggle button groups (platform / source selectors) */
.toggle-group {
    display: flex;
    gap: 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
}

.toggle-btn {
    flex: 1;
    padding: 8px 14px;
    background: var(--surface-v);
    color: var(--t2);
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.15s;
    border-right: 1px solid var(--glass-border);
}

.toggle-btn:last-child { border-right: none; }

.toggle-btn:hover {
    background: var(--surface-el);
    color: var(--t1);
}

.toggle-btn.active {
    background: var(--grad);
    color: #fff;
}

/* Mobile hamburger button — big touch target */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1001;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    color: var(--t1);
    font-size: 24px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: rgba(124, 58, 237, 0.3);
    touch-action: manipulation;
    user-select: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.mobile-menu-btn:active {
    background: var(--brand-purple);
    transform: scale(0.95);
}

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 999;
}

/* ===== Panel Download Playlist en modal Edit Line ===== */
.playlist-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.playlist-row:last-child { border-bottom: none; }
.playlist-row .playlist-label {
    font-size: 11px;
    color: var(--t3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-width: 80px;
}
.playlist-row .playlist-val {
    flex: 1;
    font-family: monospace;
    font-size: 13px;
    word-break: break-all;
}

.playlist-url-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg);
    border-radius: 8px;
    margin-bottom: 8px;
}
.playlist-url-row > div:first-child {
    flex: 1;
    min-width: 0;
}
.playlist-url-box {
    background: var(--surface-v);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 8px 10px;
    margin-top: 4px;
    font-family: monospace;
    font-size: 11px;
    word-break: break-all;
    max-height: 60px;
    overflow-y: auto;
}

/* ===== Mobile line cards (shown instead of table on mobile) ===== */
.mobile-lines-list { display: none; }

.line-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 10px;
}

.line-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}

.line-card-user {
    font-weight: 700;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.line-card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    font-size: 12px;
    color: var(--t2);
    margin-bottom: 10px;
    overflow: hidden;
}

.line-card-body .lc-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--t3);
}

.line-card-body .lc-val {
    font-weight: 600;
    color: var(--t1);
    overflow: hidden;
    text-overflow: ellipsis;
}

.line-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.line-card-actions .btn {
    display: flex;
    justify-content: center;
    min-width: 0;
    white-space: nowrap;
    font-size: 11px;
    padding: 10px 2px;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* ============================================================
   MOBILE — max-width 900px
   ============================================================ */
@media (max-width: 900px) {

    /* === GLOBAL OVERFLOW PROTECTION === */
    html, body { overflow-x: hidden; }

    /* Show hamburger */
    .mobile-menu-btn { display: flex; }

    /* Grid → single column */
    .app-wrap { grid-template-columns: 1fr; }

    /* === SIDEBAR DRAWER === */
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transition: left 0.25s ease;
        width: 250px;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        box-shadow: 8px 0 30px rgba(0,0,0,0.5);
        padding-bottom: 24px;
        display: flex;
        flex-direction: column;
    }
    .sidebar.open { left: 0; }
    .mobile-overlay.open { display: block; }

    /* Kill the flex spacer so sidebar scrolls all items */
    .sidebar > div[style*="flex:1"],
    .sidebar > div[style*="flex: 1"] { flex: 0 0 auto !important; min-height: 20px; }

    /* Nav items: big touch targets */
    .nav-item {
        padding: 14px 20px;
        font-size: 14px;
        min-height: 48px;
        flex-shrink: 0;
    }

    /* === MAIN CONTENT === */
    .main {
        padding: 12px;
        padding-top: 64px;
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* === TOPBAR === */
    .topbar {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
        margin-bottom: 12px;
    }
    .topbar h1 {
        font-size: 18px;
        padding-left: 52px;
    }
    .topbar > div {
        width: 100%;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    .credit-pill { font-size: 11px; padding: 5px 10px; }
    .user-chip { font-size: 11px; padding: 4px 8px; }
    .user-chip .role { font-size: 9px; }

    /* === STATS GRID === */
    .stats-grid { grid-template-columns: 1fr 1fr !important; gap: 8px !important; margin-bottom: 12px !important; }
    .stat-card { padding: 10px 12px !important; overflow: hidden; }
    .stat-value { font-size: 18px !important; overflow: hidden; text-overflow: ellipsis; }
    .stat-label { font-size: 9px !important; }

    /* === TOOLBAR — all sections === */
    .toolbar {
        flex-wrap: wrap;
        gap: 6px;
        margin-bottom: 10px;
    }
    .toolbar input[type="search"] {
        width: 100% !important;
        font-size: 16px;  /* prevents iOS zoom on focus */
    }
    .toolbar .spacer { display: none; }
    .toolbar .btn {
        flex: 1 1 calc(50% - 4px);
        justify-content: center;
        min-width: 0;
        font-size: 11px;
        padding: 10px 6px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* === ALL BUTTONS — prevent text overflow === */
    .btn {
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 100%;
    }
    .btn-sm { font-size: 11px; padding: 8px 8px; }

    /* === LINES: cards instead of table === */
    #view-lines .table-wrap { display: none !important; }
    .mobile-lines-list { display: block !important; }

    /* === TABLES (Live, Trending, Advisors, Audit, Messages, etc.) === */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 500px; font-size: 11px; }
    th, td { padding: 8px 5px; }

    /* Small tables in salesguide/helpguide/finance-expenses: NO min-width */
    #view-salesguide table,
    #view-helpguide table,
    #view-finance table { min-width: 0 !important; font-size: 12px; }

    /* === MODAL === */
    .modal-backdrop { padding: 0; padding-top: 60px; align-items: flex-end; }
    .modal {
        padding: 20px 16px;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 90vh;
        overflow-x: hidden;
    }
    .modal h2 { font-size: 16px; margin-bottom: 12px; }
    .modal-actions { flex-direction: column; gap: 8px; }
    .modal-actions .btn {
        width: 100%;
        justify-content: center;
        padding: 14px;
        font-size: 14px;
        white-space: normal !important;
    }
    /* Modal inner cards/flex containers */
    .modal .card { padding: 12px; overflow: hidden; }
    .modal .card > div[style*="display:flex"] { flex-wrap: wrap !important; gap: 8px !important; }
    .modal .stats-grid { grid-template-columns: 1fr !important; }
    .modal code { word-break: break-all; }
    .modal input, .modal select, .modal textarea { font-size: 16px; }

    /* === TOGGLE GROUPS === */
    .toggle-group { flex-wrap: wrap; border-radius: 8px; }
    .toggle-btn {
        font-size: 12px;
        padding: 10px 8px;
        flex: 1 1 auto;
        min-width: 0;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* === RESPONSIVE GRID CLASSES (override inline styles) === */
    .resp-grid-2-1 { grid-template-columns: 1fr !important; }
    .resp-grid-half { grid-template-columns: 1fr !important; }
    .resp-grid-third { grid-template-columns: 1fr !important; }

    /* === FINANCE === */
    #view-finance .stats-grid { grid-template-columns: 1fr 1fr !important; }
    /* Finance tab bar: wrap into 2 rows */
    #view-finance > div:first-child {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    .finance-tab {
        font-size: 11px !important;
        padding: 8px 10px !important;
        white-space: nowrap !important;
        flex: 1 1 auto !important;
        text-align: center;
    }

    /* === INTELLIGENCE === */
    #intel-pricing { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    #intel-pricing table { min-width: 650px !important; }
    /* Calendar items — stack on mobile */
    #intel-calendar > div { grid-template-columns: 1fr !important; }

    /* === SALESGUIDE — all inline grids to 1 column === */
    #view-salesguide div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    #view-salesguide { overflow-x: hidden; }
    /* Script text boxes — allow wrapping */
    #view-salesguide div[style*="white-space:pre-line"] {
        white-space: pre-wrap !important;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* === HELPGUIDE — all inline grids to 1 column === */
    #view-helpguide div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    #view-helpguide { overflow-x: hidden; }

    /* === BLOCKED (En caso de bloqueo) — tambien apilar y break URLs largas === */
    #view-blocked div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    #view-blocked { overflow-x: hidden; }
    #view-blocked code { word-break: break-all; font-size: 11px !important; }
    #view-blocked div[style*="white-space:pre-line"] {
        white-space: pre-wrap !important;
        word-break: break-word;
    }

    /* === PROXY === */
    #view-proxy { overflow-x: hidden; }
    /* Proxy server cards generated by JS */
    #proxy-servers-grid > div { overflow: hidden; word-break: break-word; }
    #proxy-servers-grid div[style*="font-family:monospace"] {
        font-size: 11px !important;
        word-break: break-all;
    }

    /* === VPN table — many columns === */
    #view-vpn table { min-width: 700px !important; }

    /* === CONFIG cards === */
    #config-grid .stat-card { overflow: hidden; word-break: break-word; }

    /* === TOAST — bottom on mobile === */
    .toast-container { left: 12px; right: 12px; top: auto; bottom: 20px; }
    .toast { min-width: auto; max-width: 100%; }

    /* === SECTION-LEVEL overflow protection === */
    section { overflow-x: hidden; }
}

/* ============================================================
   EXTRA SMALL PHONES — max-width 400px
   ============================================================ */
@media (max-width: 400px) {
    .stats-grid { grid-template-columns: 1fr !important; }
    .line-card-body { grid-template-columns: 1fr; }
    .line-card-actions { grid-template-columns: 1fr; }
    .line-card-actions .btn { font-size: 13px; padding: 12px 8px; }
    .toolbar .btn { flex: 1 1 100%; }
    .topbar h1 { font-size: 16px; }
}
