/* Reglas compartidas para que las cuadrículas no fuercen el ancho de la pantalla. */
.shell, .workspace, .results, .panel, .detail-grid > *, .bulk-layout > * {
    min-width: 0;
}
.page-heading > div { min-width: 0; }
.page-heading h1 { overflow-wrap: anywhere; }
.mobile-sort, .table-scroll-hint, .chart-swipe { display: none; }

@media (max-width: 900px) {
    .workspace, .bulk-layout, .login-layout {
        grid-template-columns: minmax(0, 1fr);
    }
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filters form {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: 16px;
    }
    .filters form > label, .filters form > button, .filters form > .reset {
        min-width: 0;
    }
    .filters .checkbox, .filters button, .filters .reset {
        grid-column: 1 / -1;
    }
    .login-layout { max-width: 520px; }
}

@media (max-width: 650px) {
    .topbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px 12px;
        padding: 12px 16px 0;
        height: auto;
    }
    .topbar .brand { grid-column: 1; grid-row: 1; min-width: 0; }
    .topbar > form { grid-column: 2; grid-row: 1; margin: 0; }
    .topbar .quiet { min-height: 40px; padding: 7px 8px; }
    .topbar nav {
        grid-column: 1 / -1;
        grid-row: 2;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
        height: 44px;
        gap: 0;
        order: initial;
    }
    .topbar nav a { height: 44px; justify-content: center; padding: 0; }

    .shell { padding: 20px 16px; }
    .page-heading { flex-direction: column; align-items: stretch; gap: 14px; }
    .page-heading h1 { font-size: 28px; line-height: 1.18; }
    .page-heading form, .page-heading > a.button { width: 100%; }
    .page-heading button { width: 100%; min-height: 44px; }
    .panel { padding: 18px; }

    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stats > div { min-width: 0; padding: 14px; }
    .stats strong { overflow-wrap: anywhere; }
    .schedule-value { font-size: 16px !important; }
    .worker-bar {
        display: grid;
        grid-template-columns: 8px minmax(0, 1fr);
        gap: 5px 9px;
    }
    .worker-bar .status-dot { grid-column: 1; grid-row: 1; margin-top: 5px; }
    .worker-bar > :not(.status-dot) {
        grid-column: 2;
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .worker-bar .next-run { width: auto; margin: 0; }

    .workspace, .settings-grid, .detail-grid, .bulk-layout {
        grid-template-columns: minmax(0, 1fr);
    }
    .filters form { column-gap: 10px; }
    .filters form > .filter-wide { grid-column: 1 / -1; }
    .filters form label { margin-bottom: 14px; }
    .filters input, .filters select, .settings-grid input,
    .settings-grid select, .login-panel input, textarea {
        font-size: 16px;
    }
    .results-heading { align-items: stretch; flex-direction: column; }
    .results-heading .button { width: 100%; }
    .cards { grid-template-columns: minmax(0, 1fr); }
    .detected-channels { flex-wrap: wrap; }
    .pagination { flex-wrap: wrap; gap: 10px; }
    .pagination .button { min-height: 44px; }
    .bulk-actions > * { width: 100%; }
    .chart-tabs .button { min-height: 44px; }
    .chart-panel { overflow: hidden; }
    .chart-overflow { margin: 0 -8px; padding: 0 8px 8px; }
    .history-chart { min-width: 600px; }
    footer { padding: 24px 16px; overflow-wrap: anywhere; }

    /* Las tablas breves se leen como fichas sin desplazamiento horizontal. */
    .mobile-table, .mobile-table tbody, .mobile-table tr, .mobile-table td {
        display: block;
        width: 100%;
    }
    .mobile-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
    .mobile-table tr {
        padding: 8px 12px;
        margin-bottom: 10px;
        border: 1px solid #e0e6ee;
        border-radius: 9px;
    }
    .mobile-table tr:last-child { margin-bottom: 0; }
    .mobile-table td {
        display: grid;
        grid-template-columns: minmax(95px, 39%) minmax(0, 1fr);
        gap: 8px;
        padding: 10px 0;
        overflow-wrap: anywhere;
        text-align: left;
    }
    .mobile-table td:last-child { border-bottom: 0; }
    .mobile-table td::before {
        content: attr(data-label);
        color: #738398;
        font-size: 11px;
        font-weight: 600;
    }
    .mobile-table td[colspan] { display: block; }
    .mobile-table td[colspan]::before { display: none; }
    .mobile-table .channel-identity { min-width: 0; }
    .mobile-table .channel-identity strong { overflow-wrap: anywhere; }

    /* La tabla de seguimiento necesita sus cifras y controles en cada ficha. */
    .mobile-sort {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0 10px;
        margin-bottom: 14px;
    }
    .mobile-sort label { min-width: 0; margin-bottom: 12px; }
    .mobile-sort button { grid-column: 1 / -1; min-height: 44px; }
    .channel-panel { padding: 10px; overflow: visible; }
    .channel-table, .channel-table tbody, .channel-table tr {
        display: block;
        width: 100%;
        min-width: 0;
    }
    .channel-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
    .channel-table tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0 10px;
        padding: 12px;
        margin-bottom: 10px;
        border: 1px solid #e0e6ee;
        border-radius: 9px;
    }
    .channel-table tr:last-child { margin-bottom: 0; }
    .channel-table .pinned-row td:first-child { box-shadow: none; }
    .channel-table td {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        min-width: 0;
        padding: 9px 0;
        text-align: left !important;
        white-space: normal;
        overflow-wrap: anywhere;
    }
    .channel-table td::before {
        content: attr(data-label);
        margin-bottom: 5px;
        color: #738398;
        font-size: 10px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: .3px;
    }
    .channel-table td:first-child,
    .channel-table td:nth-child(9),
    .channel-table td:nth-child(10) {
        grid-column: 1 / -1;
    }
    .channel-table td:first-child::before,
    .channel-table td[colspan]::before { display: none; }
    .channel-table td:first-child {
        border-bottom: 1px solid #e7ecf3;
        padding-bottom: 12px;
    }
    .channel-table td:nth-child(9) { border-top: 1px solid #e7ecf3; }
    .channel-table td:nth-child(10) { border-bottom: 0; }
    .channel-table .channel-identity { width: 100%; gap: 8px; }
    .channel-table .channel-identity strong { font-size: 14px; }
    .channel-table .pin-actions { width: 72px; gap: 4px; }
    .channel-table .move-controls { width: 28px; height: 44px; }
    .channel-table .move-button {
        width: 28px;
        height: 22px;
        font-size: 18px;
    }
    .channel-table .pin-star { width: 40px; height: 44px; font-size: 28px; }
    .channel-table .avatar, .channel-table .avatar img {
        width: 32px;
        height: 32px;
    }
    .channel-table .metric-link { font-size: 15px; }
    .channel-table .toggle-button { width: 100%; min-height: 44px; }
    .channel-table td:nth-child(10) form { width: 100%; }
}

@media (min-width: 651px) and (max-width: 1240px) {
    .table-scroll-hint { display: block; margin-bottom: 8px; }
}
@media (max-width: 650px) {
    .chart-swipe { display: block; margin: 6px 0 12px; }
    .history-compare-fields { grid-template-columns: 1fr; }
    .channel-remove summary, .channel-remove button { min-height: 44px; padding: 12px 8px; }
    .bulk-hide-toolbar button { margin-left: 0; }
}
@media (max-width: 380px) {
    .filters form { grid-template-columns: minmax(0, 1fr); }
    .filters form > label { grid-column: 1; }
}

@media (max-width:650px){
    .channel-table .channel-identity{flex-wrap:wrap}
    .channel-table .channel-view-link{margin-left:auto;min-height:36px;padding:8px 12px}
    .follow-button,.follow-badge{min-height:36px;padding:8px 12px}
}

@media (max-width:900px){
    .topbar .brand{font-size:15px}
    .topbar nav a{padding:0 9px}
}
@media (max-width:650px){
    .topbar{padding-bottom:12px}
    .topbar .brand{font-size:14px;gap:7px;white-space:normal;line-height:1.15}
    .topbar .brand-icon{width:30px;height:30px}
    .topbar nav{height:auto;gap:4px;padding:4px}
    .topbar nav a{height:42px;gap:5px;padding:0 5px;font-size:12px}
    .topbar nav svg{width:16px;height:16px}
    .channel-add-actions{display:grid;grid-template-columns:minmax(0,1fr);gap:9px}
    .channel-add-actions .button,.channel-add-actions button{width:100%;min-height:44px;text-align:center}
}
@media (max-width:380px){
    .topbar .brand{font-size:12.5px}
    .topbar nav a{flex-direction:column;gap:1px;font-size:11px;line-height:1}
    .topbar nav svg{width:15px;height:15px}
}

@media (max-width:650px){
    .invite-association-fields{flex-direction:column;align-items:stretch}
    .invite-association-fields input,.invite-association-fields button{width:100%;min-height:44px}
}

@media(max-width:650px){.kind-tabs{margin-left:0;display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:2px}.kind-tabs a{text-align:center;padding:9px 3px;font-size:10px}}
@media(min-width:651px) and (max-width:1100px){.results-heading{flex-wrap:wrap}.kind-tabs{margin-left:auto}}

@media (max-width: 650px) {
    .account-statuses { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .account-status { min-width: 0; padding: 11px; }
}

@media (max-width:650px){
    .ad-filter-toolbar{display:grid;grid-template-columns:minmax(0,1fr);gap:9px}
    .ad-filter-group{width:100%}
    .ad-filter-group>span{flex-basis:100%;padding:3px 7px 0}
    .ad-filter-group a{min-height:40px;flex:1;padding:7px 6px}
    .eye-button{width:44px;height:44px}
    .results .pagination{gap:6px}
    .results .pagination a{min-width:44px;min-height:44px}
    .results .pagination .page-control{font-size:11px}
}

@media (max-width:650px){.manual-actions{display:grid;grid-template-columns:1fr;gap:8px}.manual-actions button{width:100%}}
