/* ── Reset / base ─────────────────────────────────────────── */
* { box-sizing: border-box; }
body {
    font-family: Arial, sans-serif;
    padding: 20px;
    background: #f0f2f5;
    margin: 0;
}
.container { width: 100%; }

/* ── Tipografía ───────────────────────────────────────────── */
h1, h2, h3 { margin-top: 0; color: #343a40; }
h1 { font-size: 1.3em; }

/* ── Top bar / nav ────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}
.topbar h1 { margin: 0; font-size: 1.3em; color: #212529; }

.server-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.server-selector label {
    font-weight: bold;
    font-size: 0.9em;
    color: #495057;
    white-space: nowrap;
}
.server-selector select {
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
}

.server-pill {
    display: inline-block;
    background: #e9ecef;
    color: #495057;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.82em;
}
.server-pill.active { background: #007bff; color: white; }

.btn-config-servers {
    padding: 6px 12px;
    background: #6f42c1;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    text-decoration: none;
    display: inline-block;
}
.btn-config-servers:hover { background: #5a2d9c; }

/* ── Cards y status ───────────────────────────────────────── */
.card {
    background: white;
    border: 1px solid #dee2e6;
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 6px;
}
.status {
    padding: 10px 14px;
    border-radius: 4px;
    font-weight: bold;
    margin-bottom: 20px;
}
.status.ok { background: #d4edda; color: #155724; }
.status.error { background: #f8d7da; color: #721c24; }
.status.no-server { background: #fff3cd; color: #856404; }

/* ── Formularios ──────────────────────────────────────────── */
label { display: block; font-weight: bold; font-size: 0.85em; color: #495057; margin: 10px 0 3px; }
input[type="text"], input[type="password"], select, textarea {
    width: 100%;
    padding: 8px;
    margin-bottom: 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
}

/* ── Botones ─────────────────────────────────────────────── */
button, .btn {
    padding: 9px 14px;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9em;
    text-decoration: none;
    display: inline-block;
}
button.btn-primary, .btn-primary { background: #007bff; color: white; }
button.btn-primary:hover { background: #0056b3; }
button.btn-sm, .btn-sm { padding: 5px 10px; font-size: 0.82em; }
button.btn-warning, .btn-warning { background: #fd7e14; color: white; }
button.btn-warning:hover { background: #e96b02; }
button.btn-danger, .btn-danger { background: #dc3545; color: white; }
button.btn-danger:hover { background: #b02a37; }
button.btn-success, .btn-success { background: #28a745; color: white; }
.btn-success:hover { background: #218838; }
.btn-cancel { padding: 9px 14px; background: #6c757d; color: white; }
.btn-cancel:hover { background: #5a6268; }

button:disabled, .btn-loading:disabled { cursor: not-allowed; opacity: 0.75; }

/* ── Button loading effect ────────────────────────────────── */
.btn-loading {
    position: relative;
    overflow: hidden;
}
.btn-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, rgba(0,0,0,0.22), rgba(0,0,0,0.45));
    z-index: 1;
}
.btn-loading.loading::before {
    animation: btnLoadingLoop 2s ease-in-out infinite;
}
@keyframes btnLoadingLoop {
    0%   { width: 0%; left: 0; }
    50%  { width: 100%; left: 0; }
    51%  { width: 100%; left: 100%; }
    100% { width: 0%; left: 100%; }
}
.btn-loading span { position: relative; z-index: 2; }

/* ── Tablas ───────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82em;
    white-space: nowrap;
}
table th, table td {
    border: 1px solid #dee2e6;
    padding: 6px 8px;
    text-align: left;
    vertical-align: middle;
}
table th { background: #343a40; color: white; }
table tr:nth-child(even) { background: #f8f9fa; }
table tr:hover { background: #e9ecef; }

th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 18px;
}
th.sortable:hover { background: #495057; }
th.sortable::after { content: '↕'; position: absolute; right: 6px; color: #adb5bd; font-size: 0.85em; }
th.sortable.asc::after { content: '↑'; color: #fff; }
th.sortable.desc::after { content: '↓'; color: #fff; }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.8em;
}
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-count { background: #007bff; color: white; padding: 3px 10px; border-radius: 12px; font-size: 0.9em; }

/* ── Tablas de usuarios / roles ───────────────────────────── */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.install-table {
    table-layout: fixed;
    width: 100%;
    min-width: 0;
    border-collapse: collapse;
}

.install-table th,
.install-table td {
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
    vertical-align: top;
    padding: 8px;
}

.install-table .permissions-cell {
    width: 25%;
    white-space: normal;
}

.install-table .actions-cell {
    white-space: normal;
    width: auto;
    min-width: 90px;
}

.install-table .actions-cell form,
.install-table .actions-cell a {
    display: inline-block;
    margin: 2px 0;
}

.install-table .permissions-badge {
    margin: 2px;
    display: inline-block;
    white-space: normal;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Anchos específicos para evitar desbordamiento */
.install-table.roles-table th:nth-child(1),
.install-table.roles-table td:nth-child(1) { width: 8%; }
.install-table.roles-table th:nth-child(2),
.install-table.roles-table td:nth-child(2) { width: 22%; }
.install-table.roles-table th:nth-child(3),
.install-table.roles-table td:nth-child(3) { width: 12%; }
.install-table.roles-table th:nth-child(4),
.install-table.roles-table td:nth-child(4) { width: 43%; }
.install-table.roles-table th:nth-child(5),
.install-table.roles-table td:nth-child(5) { width: 15%; }

.install-table.users-table th:nth-child(1),
.install-table.users-table td:nth-child(1) { width: 5%; }
.install-table.users-table th:nth-child(2),
.install-table.users-table td:nth-child(2) { width: 13%; }
.install-table.users-table th:nth-child(3),
.install-table.users-table td:nth-child(3) { width: 16%; }
.install-table.users-table th:nth-child(4),
.install-table.users-table td:nth-child(4) { width: 11%; }
.install-table.users-table th:nth-child(5),
.install-table.users-table td:nth-child(5) { width: 25%; }
.install-table.users-table th:nth-child(6),
.install-table.users-table td:nth-child(6) { width: 7%; }
.install-table.users-table th:nth-child(7),
.install-table.users-table td:nth-child(7) { width: 14%; }
.install-table.users-table th:nth-child(8),
.install-table.users-table td:nth-child(8) { width: 10%; }

@media (max-width: 900px) {
    .table-responsive {
        border: 1px solid #e2e8f0;
        border-radius: 6px;
    }
    .install-table .permissions-cell,
    .install-table .actions-cell {
        width: auto;
        min-width: 0;
    }
    .install-table th,
    .install-table td {
        padding: 6px;
    }
}

/* ── Modales ──────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: white;
    border-radius: 8px;
    width: 520px;
    max-width: 92%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 5px 30px rgba(0,0,0,0.3);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}
.modal-header h3 { margin: 0; font-size: 1.05em; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: #666;
    padding: 0 5px;
}
.modal-close:hover { color: #333; }
.modal-body { padding: 20px; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid #dee2e6;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ── Loading overlay ──────────────────────────────────────── */
#action-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.65);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #fff;
}
#action-overlay.visible { display: flex; }
#action-overlay .spinner {
    width: 48px; height: 48px;
    border: 5px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: action-spin 1s linear infinite;
    margin-bottom: 16px;
}
#action-overlay .message { font-size: 1.1em; font-weight: 500; }
@keyframes action-spin { to { transform: rotate(360deg); } }

/* ── Toast ────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 20px; right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.toast {
    min-width: 280px;
    max-width: 420px;
    padding: 12px 16px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    color: #fff;
    font-size: 0.95em;
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: slideIn 0.3s ease;
    cursor: pointer;
}
.toast-success { background: #28a745; }
.toast-error { background: #dc3545; }
.toast-warning { background: #fd7e14; }
.toast-info { background: #007bff; }
.toast-close { margin-left: 10px; font-weight: bold; font-size: 1.1em; line-height: 1; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(100%); } }
.toast.hiding { animation: fadeOut 0.3s ease forwards; }

/* ── Utilidades ───────────────────────────────────────────── */
.hidden-scroll { display: none !important; }
.hidden-filter { display: none !important; }
.alert { padding: 10px 14px; margin-bottom: 15px; border-radius: 4px; }
.alert-success { background: #d4edda; color: #155724; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.text-right { text-align: right; }
.text-muted { color: #6c757d; }
