/* =========================================================
   EXPLANNER — SITE.CSS LIMPIO Y RESPONSIVE
   ========================================================= */

/* Base */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    overflow-x: hidden;
    background: #f4f6f9;
    font-family: Arial, Helvetica, sans-serif;
}

input,
select,
textarea,
button,
.form-control,
.form-select {
    max-width: 100%;
}

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

.app-content {
    flex: 1;
    min-width: 0;
    max-width: 100%;
}

.main-area {
    min-width: 0;
    max-width: 100%;
    padding: 24px;
}

/* Sidebar */
.sidebar {
    flex: 0 0 235px;
    width: 235px;
    padding: 22px 16px;
    background: #172033;
    color: #fff;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}

.brand > span,
.login-logo {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    flex: 0 0 44px;
    border-radius: 12px;
    background: #2563eb;
    color: #fff;
    font-weight: 700;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: #aeb8cc;
}

.sidebar-nav,
.sidebar nav {
    display: grid;
    gap: 6px;
}

.sidebar-link,
.sidebar nav a {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: #cbd5e1;
    text-decoration: none;
}

.sidebar-link:hover,
.sidebar-link:focus,
.sidebar nav a:hover,
.sidebar nav a:focus {
    background: #26344f;
    color: #fff;
    outline: none;
}

.sidebar-close,
.menu-toggle,
.sidebar-overlay {
    display: none;
}

/* Topbar */
.topbar {
    display: flex;
    min-height: 64px;
    padding: 12px 24px;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 1px solid #e3e7ed;
    background: #fff;
}

.topbar-left,
.topbar-account {
    display: flex;
    align-items: center;
}

.topbar-left {
    min-width: 0;
    gap: 12px;
}

.topbar-account {
    flex: 0 0 auto;
    gap: 14px;
}

.topbar-title {
    min-width: 0;
}

.topbar-title > span {
    display: block;
    overflow: hidden;
    color: #172033;
    font-size: 1.05rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-text {
    display: grid;
    gap: 0;
    text-align: right;
}

.account-text strong {
    font-size: .86rem;
}

.account-text span {
    color: #667085;
    font-size: .75rem;
}

.role {
    display: inline-flex;
    padding: 4px 9px;
    border-radius: 999px;
    background: #e8eefc;
    color: #24499a;
    font-size: .78rem;
    font-weight: 600;
}

/* Encabezados */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-header h1 {
    margin: 0;
}

.page-subtitle {
    margin: 4px 0 0;
    color: #667085;
}

.results-summary {
    margin: -6px 0 12px;
    color: #667085;
    font-size: .9rem;
}

/* Tarjetas */
.summary-card,
.form-card,
.filter-card,
.detail-card,
.dashboard-card {
    padding: 20px;
    border: 1px solid #e1e6ed;
    border-radius: 12px;
    background: #fff;
}

.summary-card span,
.summary-card strong {
    display: block;
}

.summary-card span {
    margin-bottom: 8px;
    color: #667085;
}

.filter-card {
    margin-bottom: 18px;
}

/* Login */
.auth-area {
    display: grid;
    min-height: 100vh;
    padding: 24px;
    place-items: center;
    background: #edf1f7;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 30px;
    border: 1px solid #dde3eb;
    border-radius: 16px;
    background: #fff;
    text-align: center;
}

.login-card form {
    text-align: left;
}

.login-logo {
    margin: 0 auto 14px;
}

/* Buscadores y autocomplete */
.search-input-wrapper,
.autocomplete-container {
    position: relative;
}

.search-indicator {
    position: absolute;
    top: 50%;
    right: 12px;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    border: 2px solid #cbd5e1;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: search-spin .7s linear infinite;
}

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

.autocomplete-results {
    position: absolute;
    z-index: 1050;
    top: calc(100% + 4px);
    right: 0;
    left: 0;
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid #d8dee8;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 14px 35px rgba(23, 32, 51, .16);
}

.autocomplete-item {
    display: flex;
    width: 100%;
    padding: 10px 12px;
    flex-direction: column;
    gap: 2px;
    border: 0;
    border-bottom: 1px solid #eef1f5;
    background: #fff;
    text-align: left;
}

.autocomplete-item:last-child {
    border-bottom: 0;
}

.autocomplete-item:hover,
.autocomplete-item:focus {
    background: #f1f5ff;
    outline: none;
}

.autocomplete-item span {
    color: #667085;
    font-size: .84rem;
}

.lookup-status {
    min-height: 22px;
    font-size: .9rem;
}

.lookup-muted {
    color: #667085;
}

.lookup-success {
    color: #16794b;
}

.lookup-warning {
    color: #9a6700;
}

.lookup-danger {
    color: #b42318;
}

/* Estados */
.status-badge {
    display: inline-flex;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
}

.status-active {
    background: #dcfce7;
    color: #166534;
}

.status-inactive {
    background: #fee2e2;
    color: #991b1b;
}

.reason-cell {
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.dashboard-card {
    border-radius: 14px;
    box-shadow: 0 4px 14px rgba(23, 32, 51, .04);
}

.dashboard-kpi,
.dashboard-action {
    display: flex;
    min-height: 150px;
    flex-direction: column;
    justify-content: center;
}

.dashboard-label,
.dashboard-card small {
    color: #667085;
}

.dashboard-label {
    font-size: .9rem;
}

.dashboard-value {
    margin: 6px 0;
    font-size: 2.15rem;
    line-height: 1;
}

.dashboard-code {
    font-size: 1.65rem;
    overflow-wrap: anywhere;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.section-heading h2 {
    margin: 0;
    font-size: 1.15rem;
}

.section-heading p {
    margin: 3px 0 0;
    color: #667085;
    font-size: .9rem;
}

.upcoming-list {
    display: grid;
    gap: 8px;
}

.upcoming-item {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 11px 12px;
    border-radius: 10px;
    color: inherit;
    text-decoration: none;
    transition: background .15s ease;
}

.upcoming-item:hover {
    background: #f5f7fb;
    color: inherit;
}

.upcoming-date {
    display: grid;
    min-height: 48px;
    place-items: center;
    align-content: center;
    border-radius: 9px;
    background: #eef3ff;
    color: #24499a;
}

.upcoming-date strong,
.upcoming-date span {
    line-height: 1;
}

.upcoming-date span {
    margin-top: 4px;
    font-size: .72rem;
    text-transform: uppercase;
}

.upcoming-content {
    min-width: 0;
}

.upcoming-content strong,
.upcoming-content span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upcoming-content span,
.upcoming-schedule {
    color: #667085;
    font-size: .86rem;
}

.empty-state {
    padding: 26px;
    border-radius: 10px;
    background: #f7f8fa;
    color: #667085;
    text-align: center;
}

/* Tablas */
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
}

.table {
    margin-bottom: 0;
}

.table th,
.table td {
    vertical-align: middle;
}

/* =========================================================
   TABLET Y MÓVIL
   ========================================================= */

@media (max-width: 992px) {
    body.menu-open {
        overflow: hidden;
    }

    .app-shell {
        display: block;
    }

    .sidebar {
        position: fixed;
        z-index: 2100;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(82vw, 290px);
        height: 100dvh;
        padding: 18px 16px;
        overflow-y: auto;
        transform: translateX(-105%);
        transition: transform .22s ease;
        box-shadow: 14px 0 35px rgba(15, 23, 42, .25);
    }

    body.menu-open .sidebar {
        transform: translateX(0);
    }

    .sidebar .brand {
        margin: 0;
    }

    .sidebar-nav,
    .sidebar nav {
        display: grid;
        grid-template-columns: 1fr;
        gap: 7px;
        width: 100%;
        margin-top: 24px;
    }

    .sidebar-link,
    .sidebar nav a {
        width: 100%;
        padding: 11px 12px;
        white-space: normal;
    }

    .sidebar-close {
        display: grid;
        width: 38px;
        height: 38px;
        padding: 0;
        place-items: center;
        flex: 0 0 38px;
        border: 0;
        border-radius: 8px;
        background: rgba(255, 255, 255, .08);
        color: #fff;
        font-size: 1.6rem;
        line-height: 1;
    }

    .sidebar-overlay {
        position: fixed;
        z-index: 2050;
        inset: 0;
        display: block;
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
        background: rgba(15, 23, 42, .48);
        transition: opacity .2s ease, visibility .2s ease;
    }

    body.menu-open .sidebar-overlay {
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
    }

    .topbar {
        position: sticky;
        z-index: 1000;
        top: 0;
        min-height: 58px;
        padding: 10px 16px;
    }

    .menu-toggle {
        display: grid;
        width: 38px;
        height: 38px;
        padding: 0;
        place-content: center;
        gap: 4px;
        flex: 0 0 38px;
        border: 0;
        border-radius: 8px;
        background: transparent;
    }

    .menu-toggle:hover {
        background: #eef2f7;
    }

    .menu-toggle span {
        display: block;
        width: 20px;
        height: 2px;
        border-radius: 3px;
        background: #172033;
    }

    .main-area {
        padding: 18px;
    }

    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-action {
        grid-column: 1 / -1;
        min-height: auto;
    }

    .filter-card .row {
        row-gap: 12px;
    }

    .table {
        min-width: 780px;
    }

    .table th,
    .table td {
        padding: 10px 9px;
        font-size: .9rem;
    }
}

@media (max-width: 768px) {
    .topbar {
        min-height: 56px;
        padding: 8px 12px;
    }

    .topbar-left {
        gap: 8px;
    }

    .topbar-title > span {
        font-size: .98rem;
    }

    .account-text,
    .role {
        display: none;
    }

    .topbar-account {
        gap: 0;
    }

    .topbar-account form {
        margin: 0;
    }

    .topbar-account .btn {
        min-height: 36px;
        padding: 6px 11px;
        font-size: .85rem;
    }

    .main-area {
        padding: 14px;
    }

    .page-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: start;
        gap: 12px;
        margin-bottom: 16px;
    }

    .page-header > div {
        min-width: 0;
    }

    .page-header h1 {
        margin: 0;
        font-size: 1.65rem;
        line-height: 1.15;
    }

    .page-subtitle {
        margin-top: 6px;
        font-size: .92rem;
        line-height: 1.45;
    }

    .page-header > .btn {
        min-width: 112px;
        padding: 9px 14px;
        white-space: normal;
    }

    .summary-card,
    .form-card,
    .filter-card,
    .detail-card,
    .dashboard-card {
        padding: 15px;
        border-radius: 11px;
    }

    .filter-card {
        margin-bottom: 14px;
    }

    .filter-card .row > div {
        width: 100%;
    }

    .filter-card .d-flex {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px !important;
    }

    .filter-card .btn-primary {
        width: 100%;
    }

    .results-summary {
        margin: 0 0 10px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .dashboard-action {
        grid-column: auto;
    }

    .dashboard-kpi,
    .dashboard-action {
        min-height: 118px;
    }

    .dashboard-value {
        font-size: 1.9rem;
    }

    .section-heading {
        align-items: flex-start;
        gap: 10px;
    }

    .upcoming-item {
        grid-template-columns: 48px minmax(0, 1fr);
        gap: 11px;
        padding: 10px;
    }

    .upcoming-schedule {
        grid-column: 2;
    }

    .autocomplete-results {
        position: fixed;
        z-index: 2200;
        top: auto;
        right: 12px;
        bottom: 12px;
        left: 12px;
        max-height: 42vh;
        border-radius: 14px;
    }

    .autocomplete-item {
        min-height: 52px;
        padding: 11px 13px;
    }
}

/* Tabla convertida en tarjetas */
@media (max-width: 640px) {
    .table-responsive {
        overflow: visible;
        border-radius: 0;
    }

    .table {
        display: block;
        min-width: 0;
        width: 100%;
        background: transparent;
    }

    .table thead {
        display: none;
    }

    .table tbody {
        display: grid;
        gap: 12px;
    }

    .table tr {
        display: block;
        padding: 12px 14px;
        border: 1px solid #e1e6ed;
        border-radius: 12px;
        background: #fff;
        box-shadow: 0 2px 8px rgba(23, 32, 51, .04);
    }

    .table td {
        display: grid;
        grid-template-columns: 92px minmax(0, 1fr);
        gap: 10px;
        width: 100%;
        padding: 7px 0;
        border: 0;
        border-bottom: 1px solid #eef1f5;
        font-size: .9rem;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .table td:last-child {
        border-bottom: 0;
    }

    .table td::before {
        color: #667085;
        font-size: .78rem;
        font-weight: 700;
        text-transform: uppercase;
    }

    .table td:nth-child(1)::before {
        content: "Fecha";
    }

    .table td:nth-child(2)::before {
        content: "Horario";
    }

    .table td:nth-child(3)::before {
        content: "Puesto";
    }

    .table td:nth-child(4)::before {
        content: "Código";
    }

    .table td:nth-child(5)::before {
        content: "Nombre";
    }

    .table td:nth-child(6)::before {
        content: "Motivo";
    }

    .table td:nth-child(7)::before {
        content: "Acciones";
    }

    .table td.text-end {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 7px;
        padding-top: 10px;
        text-align: left !important;
    }

    .table td.text-end::before {
        margin-right: auto;
    }

    .reason-cell {
        max-width: none;
        overflow: visible;
        white-space: normal;
        text-overflow: unset;
    }
}

@media (max-width: 480px) {
    .main-area {
        padding: 11px;
    }

    .topbar {
        padding-right: 10px;
        padding-left: 12px;
    }

    .topbar-title > span {
        max-width: 210px;
    }

    .page-header {
        grid-template-columns: 1fr;
    }

    .page-header > .btn {
        width: 100%;
    }

    .filter-card .d-flex {
        grid-template-columns: 1fr;
    }

    .filter-card .btn,
    .form-card .btn {
        min-height: 42px;
    }

    .form-card .mt-3.d-flex {
        display: grid !important;
        grid-template-columns: 1fr;
    }

    .form-card .mt-3.d-flex .btn {
        width: 100%;
    }

    .table tr {
        padding: 11px 12px;
    }

    .table td {
        grid-template-columns: 78px minmax(0, 1fr);
        gap: 8px;
    }

    .login-card {
        padding: 22px 18px;
        border-radius: 13px;
    }

    .auth-area {
        padding: 14px;
    }
}

/* =========================================================
   MENSAJES DE OPERACIÓN Y KPI POR ROL
   ========================================================= */
.operation-message {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(23, 32, 51, .06);
}

.operation-message .btn-close {
    margin-left: auto;
}

.dashboard-grid-supervisor {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.dashboard-grid-collaborator {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.dashboard-next-value {
    margin: 8px 0 4px;
    font-size: 1.35rem;
    line-height: 1.15;
}

.dashboard-quick-action {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px;
    border: 1px solid #e1e6ed;
    border-radius: 12px;
    background: #fff;
}

.dashboard-quick-action div {
    display: grid;
}

.dashboard-quick-action span {
    color: #667085;
    font-size: .9rem;
}

@media (max-width: 1200px) {
    .dashboard-grid-supervisor {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    .dashboard-grid-supervisor,
    .dashboard-grid-collaborator {
        grid-template-columns: 1fr;
    }

    .dashboard-quick-action {
        align-items: stretch;
        flex-direction: column;
    }

    .dashboard-quick-action .btn {
        width: 100%;
    }

    .operation-message {
        align-items: flex-start;
        flex-wrap: wrap;
    }
}
