:root {
    --primary: #2c3e50;
    --primary-light: #34495e;
    --accent: #3498db;
    --accent-hover: #2980b9;
    --success: #27ae60;
    --danger: #e74c3c;
    --warning: #f39c12;
    --bg: #ecf0f1;
    --card-bg: #ffffff;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --border: #dfe6e9;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
}

.login-box {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    margin-bottom: 8px;
    color: var(--primary);
    font-size: 28px;
}

.login-box .subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 30px;
    font-size: 14px;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    transition: border-color 0.2s;
    outline: none;
    box-sizing: border-box;
    font-family: inherit;
}

.form-group textarea {
    resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--accent);
}

.btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.98);
}

/* Un botón deshabilitado tiene que VERSE deshabilitado. Sin esto,
   `boton.disabled = true` no cambia un píxel: el usuario cree que no pasó nada,
   vuelve a hacer clic o recarga a mitad de la operación. Importa sobre todo en
   "Crear la app", que tarda minutos y cuyo generador NO es idempotente. */
.btn:disabled,
.btn[disabled] {
    opacity: .55;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

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

.btn-success:hover {
    background: #219a52;
}

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

.btn-danger:hover {
    background: #c0392b;
}

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

.error-msg {
    background: #fdecea;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    display: none;
}

/* Navbar */
.navbar {
    background: var(--primary);
    color: white;
    padding: 0 30px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.navbar h1 {
    font-size: 20px;
    font-weight: 600;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.navbar-right span {
    font-size: 14px;
    opacity: 0.9;
}

.navbar-right a {
    color: white;
    text-decoration: none;
    font-size: 14px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.navbar-right a:hover {
    opacity: 1;
}

.btn-logout {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Panel */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 30px 20px;
}

.welcome {
    margin-bottom: 30px;
}

.welcome h2 {
    font-size: 24px;
    margin-bottom: 4px;
}

.welcome p {
    color: var(--text-light);
}

.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
}

.app-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 28px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
    display: block;
    border: 2px solid transparent;
}

.app-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    border-color: var(--accent);
}

.app-card .icon {
    font-size: 36px;
    margin-bottom: 14px;
    color: var(--accent);
    line-height: 1;
    min-height: 40px;
}
.app-card .icon-img {
    width: 40px;
    height: 40px;
    display: block;
}

.app-card h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.app-card p {
    color: var(--text-light);
    font-size: 14px;
    line-height: 1.5;
}

.no-apps {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.no-apps i {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
}

/* Admin */
.admin-section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.admin-section h3 {
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.admin-table th {
    font-weight: 600;
    color: var(--text-light);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.admin-table tr:hover {
    background: #f8f9fa;
}

/* El admin usa todo el ancho de la página (la regla .container global tiene
   max-width:1100px que apretaba la tabla de usuarios) */
.container.container-admin { max-width: none; padding-left: 24px; padding-right: 24px; }

/* Tabla de usuarios: compacta, todo en una línea por fila */
.users-table th,
.users-table td { padding: 4px 8px; font-size: 13px; vertical-align: middle; }
.users-table th { font-size: 11px; white-space: nowrap; }
/* Columnas que NO deben quebrar: estado, rol, fechas, acciones */
.users-table td:nth-child(3),
.users-table td:nth-child(4),
.users-table td:nth-child(6),
.users-table td:nth-child(7) { white-space: nowrap; }
/* Acciones: colapsa al contenido para no robar ancho a las demás columnas */
.users-table th:last-child,
.users-table td:last-child { white-space: nowrap; width: 1px; }
.users-table td.email { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.users-table .btn-sm { padding: 3px 7px; font-size: 12px; line-height: 1.4; }
.users-table select { font-size: 12px; padding: 2px 4px; }
.users-table .actions { display: flex; gap: 3px; flex-wrap: nowrap; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.badge-active {
    background: #d4edda;
    color: #155724;
}

.badge-inactive {
    background: #f8d7da;
    color: #721c24;
}

.badge-admin {
    background: #d1ecf1;
    color: #0c5460;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 30px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal h3 {
    margin-bottom: 20px;
}

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

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

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: #c8d1d6;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
}

.admin-header h3 {
    margin: 0;
    padding: 0;
    border: none;
}

/* Buscador de apps (panel) */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.app-search {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    padding: 14px 0;
    margin-bottom: 8px;
}

.app-search.is-stuck {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

.app-search-field {
    position: relative;
    display: flex;
    align-items: center;
}

.app-search-icon {
    position: absolute;
    left: 16px;
    color: var(--text-light);
    font-size: 18px;
    pointer-events: none;
}

.app-search-input {
    width: 100%;
    padding: 13px 44px 13px 46px;
    border: 2px solid var(--border);
    border-radius: 999px;
    font-size: 15px;
    font-family: inherit;
    background: var(--card-bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.app-search-input::placeholder {
    color: var(--text-light);
}

.app-search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.15);
}

.app-search-clear {
    position: absolute;
    right: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-light);
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s, color 0.2s;
}

.app-search-clear:hover {
    background: var(--border);
    color: var(--text);
}

.app-search-count {
    margin-top: 8px;
    padding-left: 4px;
    font-size: 13px;
    color: var(--text-light);
}

.app-highlight {
    background: #d6eaf8;
    color: inherit;
    padding: 0 1px;
    border-radius: 3px;
}

.no-results {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-light);
}

.no-results i {
    font-size: 44px;
    margin-bottom: 14px;
    display: block;
}

@media (max-width: 600px) {
    .container {
        padding: 20px 14px;
    }
    .apps-grid {
        grid-template-columns: 1fr;
    }
}
