/* ============================================================
   global.css – Estilos principales
   Suite de Herramientas de IA – Motorpress
   ============================================================ */

/* ─── Variables ──────────────────────────────────────────── */
:root {
    --bg-base: #f8fafc;
    --bg-surface: #f1f5f9;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --sidebar-w: 260px;
    --accent: #003874;
    --accent-hover: #002855;
    --accent-cyan: #0199d2;
    --accent-soft: rgba(0, 56, 116, 0.08);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: rgba(0, 0, 0, 0.06);
    --border-strong: rgba(0, 0, 0, 0.12);
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0284c7;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 2px 8px rgba(0, 56, 116, 0.04);
    --shadow-md: 0 4px 20px rgba(0, 56, 116, 0.08);
    --shadow-lg: 0 8px 40px rgba(0, 56, 116, 0.12);
    --transition: 0.2s ease;
    --font: 'Inter', system-ui, sans-serif;
    --header-h: 56px;
}

/* ─── Reset y Base ───────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    background: var(--bg-base);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
}

img {
    max-width: 100%;
}

/* ─── Layout Principal ───────────────────────────────────── */
#app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-logo {
    padding: 20px 18px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-logo a {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo img {
    max-width: 100%;
    height: auto;
    max-height: 48px;
}

.logo-mark {
    width: 38px;
    height: 38px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    box-shadow: 0 0 16px rgba(0, 56, 116, 0.2);
}

.logo-text {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-primary);
}

.logo-text small {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

/* Navegación del sidebar */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}

.nav-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 8px 18px 4px;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    border-radius: 0;
    transition: background var(--transition), color var(--transition);
    border-left: 3px solid transparent;
    position: relative;
}

.sidebar-nav a:hover {
    background: var(--accent-soft);
    color: var(--text-primary);
}

.sidebar-nav a.active {
    background: var(--accent-soft);
    color: var(--accent);
    border-left-color: var(--accent);
}

.nav-icon {
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
}

.nav-empty {
    padding: 12px 18px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

.admin-nav {
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

/* Footer del sidebar */
.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-surface);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.user-avatar {
    width: 34px;
    height: 34px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.user-details {
    min-width: 0;
}

.user-name {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-logout {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    text-decoration: none;
    flex-shrink: 0;
}

.btn-logout:hover {
    background: rgba(217, 119, 6, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

/* ─── Main Wrapper ───────────────────────────────────────── */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Mobile Header */
.mobile-header {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: var(--header-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: relative;
    z-index: 50;
}

.mobile-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    flex: 1;
}

.mobile-logo .logo-mark {
    width: 30px;
    height: 30px;
    font-size: 12px;
}

.btn-logout-mobile {
    font-size: 18px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition);
}

.btn-logout-mobile:hover {
    color: var(--accent);
}

/* Hamburger */
.hamburger {
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 6px;
}

.hamburger span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 2px;
    transition: transform var(--transition), opacity var(--transition);
}

.hamburger.active span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* Overlay mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    backdrop-filter: blur(2px);
}

/* Main content */
#main-content {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
}

/* ─── Flash Messages ─────────────────────────────────────── */
.flash-container {
    padding: 12px 24px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    border-left: 4px solid;
    animation: slideIn 0.25s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alert-success {
    background: rgba(5, 150, 105, 0.08);
    border-color: var(--success);
    color: #065f46;
}

.alert-error {
    background: rgba(220, 38, 38, 0.08);
    border-color: var(--danger);
    color: #991b1b;
}

.alert-warning {
    background: rgba(217, 119, 6, 0.08);
    border-color: var(--warning);
    color: #854d0e;
}

.alert-info {
    background: rgba(1, 153, 210, 0.1);
    border-color: var(--accent-cyan);
    color: #0369a1;
}

.alert-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: inherit;
    opacity: 0.6;
    line-height: 1;
    padding: 0 2px;
}

.alert-close:hover {
    opacity: 1;
}

/* ─── Badges ─────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 50px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.badge-admin {
    background: rgba(220, 38, 38, 0.15);
    color: #991b1b;
}

.badge-user {
    background: rgba(1, 153, 210, 0.15);
    color: #0369a1;
}

.badge-on {
    background: rgba(5, 150, 105, 0.15);
    color: #065f46;
}

.badge-off {
    background: rgba(156, 163, 175, 0.15);
    color: #4b5563;
}

/* ─── Botones ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid transparent;
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
    line-height: 1.4;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 0 16px rgba(217, 119, 6, 0.3);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: 0 0 22px rgba(0, 40, 85, 0.3);
    color: #fff;
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-card);
    border-color: var(--accent);
    color: var(--text-primary);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: rgba(220, 38, 38, 0.4);
}

.btn-danger:hover:not(:disabled) {
    background: rgba(220, 38, 38, 0.12);
    border-color: var(--danger);
    color: var(--danger);
}

.btn-sm {
    padding: 5px 11px;
    font-size: 12px;
}

/* ─── Cards ──────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.card-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ─── Formularios ────────────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.3px;
}

.form-control {
    width: 100%;
    padding: 9px 13px;
    background: var(--bg-base);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(1, 153, 210, 0.15);
}

.form-control::placeholder {
    color: var(--text-muted);
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 90px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.form-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

.form-hint {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-error {
    color: #dc2626;
    font-size: 12px;
    margin-top: 4px;
}

/* ─── Tablas ─────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

thead th {
    background: var(--bg-elevated);
    padding: 11px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

tbody tr:last-child {
    border-bottom: none;
}

tbody tr:hover {
    background: rgba(0, 0, 0, 0.025);
}

tbody td {
    padding: 11px 16px;
    color: var(--text-primary);
    vertical-align: middle;
}

.td-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ─── Página header ──────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ─── Buscador ───────────────────────────────────────────── */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.search-bar .form-control {
    max-width: 320px;
}

/* ─── Paginación ─────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    text-decoration: none;
}

.pagination a:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.pagination .active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.pagination .disabled {
    opacity: 0.35;
    pointer-events: none;
}

/* ─── Dialog / Modal ─────────────────────────────────────── */
dialog {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 0;
    max-width: 520px;
    width: 95%;
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(3px);
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.dialog-title {
    font-size: 16px;
    font-weight: 600;
}

.dialog-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 2px;
    transition: color var(--transition);
}

.dialog-close:hover {
    color: var(--text-primary);
}

.dialog-body {
    padding: 24px;
}

.dialog-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ─── Empty State ────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 14px;
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 200;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    #main-content {
        padding: 20px 16px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .btn {
        padding: 8px 13px;
    }
}