/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --sidebar-w:     220px;
    --header-h:      56px;
    --color-bg:      #f1f5f9;
    --color-surface: #ffffff;
    --color-border:  #e2e8f0;
    --color-text:    #1e293b;
    --color-muted:   #64748b;
    --color-primary: #2563eb;
    --color-primary-h:#1d4ed8;
    --color-success: #16a34a;
    --color-error:   #dc2626;
    --color-warning: #d97706;
    --color-sidebar-bg:   #1e293b;
    --color-sidebar-text: #94a3b8;
    --color-sidebar-h:    #f1f5f9;
    --radius:        0.5rem;
    --shadow:        0 1px 3px rgb(0 0 0 / .1);
    --font:          system-ui, -apple-system, sans-serif;
}

body { font-family: var(--font); background: var(--color-bg); color: var(--color-text); font-size: .95rem; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Admin layout ─────────────────────────────────────────── */
.admin-layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    background: var(--color-sidebar-bg);
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow-y: auto;
}
.sidebar-logo {
    padding: 1.25rem 1.5rem;
    font-weight: 700;
    font-size: 1rem;
    color: var(--color-sidebar-h);
    border-bottom: 1px solid #334155;
    letter-spacing: .02em;
}
.sidebar nav {
    padding: 1rem 0;
    flex: 1;
}
.sidebar nav a {
    display: block;
    padding: .6rem 1.5rem;
    color: var(--color-sidebar-text);
    font-size: .9rem;
    transition: background .12s, color .12s;
    border-left: 3px solid transparent;
}
.sidebar nav a:hover,
.sidebar nav a.active {
    background: #334155;
    color: var(--color-sidebar-h);
    text-decoration: none;
    border-left-color: var(--color-primary);
}
.sidebar nav a.logout {
    margin-top: auto;
    color: #ef4444;
}

/* ── Admin content ────────────────────────────────────────── */
.admin-content {
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.admin-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    height: var(--header-h);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 50;
}
.admin-header h1 { font-size: 1.1rem; font-weight: 600; flex: 1; }
.user-badge {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: .25rem .85rem;
    font-size: .8rem;
    color: var(--color-muted);
}
.admin-content main { padding: 2rem; flex: 1; }

/* ── Flash messages ───────────────────────────────────────── */
.flash-messages { margin-bottom: 1.5rem; }
.flash {
    padding: .85rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: .5rem;
    font-size: .9rem;
}
.flash.success { background: #f0fdf4; border: 1px solid #bbf7d0; color: var(--color-success); }
.flash.error   { background: #fef2f2; border: 1px solid #fecaca; color: var(--color-error);   }
.flash.warning { background: #fffbeb; border: 1px solid #fde68a; color: var(--color-warning); }
.flash.notice  { background: #eff6ff; border: 1px solid #bfdbfe; color: var(--color-primary); }

/* ── Alerts (inline) ──────────────────────────────────────── */
.alert         { padding: 1rem 1.25rem; border-radius: var(--radius); margin-bottom: 1.5rem; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: var(--color-success); }
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: var(--color-error);   }

/* ── Stats grid (dashboard) ───────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}
.stat-number { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label  { color: var(--color-muted); font-size: .85rem; }

/* ── Tables ───────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    font-size: .9rem;
}
.data-table thead { background: var(--color-bg); }
.data-table th {
    text-align: left;
    padding: .75rem 1rem;
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-muted);
    border-bottom: 1px solid var(--color-border);
}
.data-table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--color-bg); }
.data-table td a { font-size: .85rem; margin-right: .75rem; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: .5rem 1.1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .12s, border-color .12s;
    text-align: center;
}
.btn-primary   { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-h); color: #fff; text-decoration: none; }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); text-decoration: none; }
.btn-danger    { background: #fef2f2; color: var(--color-error); border-color: #fecaca; }
.btn-danger:hover { background: var(--color-error); color: #fff; text-decoration: none; }

/* ── Forms ────────────────────────────────────────────────── */
.admin-form { max-width: 540px; }
.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: flex;
    flex-direction: column;
    gap: .4rem;
    font-weight: 500;
    font-size: .9rem;
}
.form-group small { color: var(--color-muted); font-weight: 400; }
.form-group input,
.form-group select,
.form-group textarea {
    padding: .55rem .85rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: .95rem;
    width: 100%;
    background: var(--color-surface);
    transition: border-color .12s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--color-primary); }

.checkbox-label { flex-direction: row !important; align-items: center; gap: .5rem !important; font-weight: 400 !important; }
.required { color: var(--color-error); }

.form-actions { display: flex; gap: .75rem; margin-top: 1.75rem; }

/* ── Danger zone ──────────────────────────────────────────── */
.danger-zone {
    margin-top: 3rem;
    padding: 1.5rem;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    background: #fef2f2;
    max-width: 540px;
}
.danger-zone h3 { font-size: .9rem; color: var(--color-error); margin-bottom: 1rem; text-transform: uppercase; letter-spacing: .05em; }

/* ── Pagination ───────────────────────────────────────────── */
.pagination {
    display: flex;
    gap: .5rem;
    align-items: center;
    margin-top: 1.5rem;
    font-size: .875rem;
}
.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 .5rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
}
.pagination a:hover { background: var(--color-bg); text-decoration: none; }
.pagination .current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.pagination .disabled { color: var(--color-muted); pointer-events: none; }

/* ── Login page ───────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    background: var(--color-sidebar-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.login-box {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 4px 24px rgb(0 0 0 / .2);
}
.login-box h1 { font-size: 1.4rem; margin-bottom: 1.5rem; }
.login-box label { display: flex; flex-direction: column; gap: .4rem; font-size: .9rem; font-weight: 500; margin-bottom: 1rem; }
.login-box input { padding: .6rem .85rem; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: .95rem; width: 100%; }
.login-box button { width: 100%; margin-top: .5rem; }
.error { color: var(--color-error); font-size: .875rem; margin-bottom: 1rem; }

/* ══════════════════════════════════════════════════════════════
   TASK ALERTS — estilo Plesk
   Bandejas persistentes en la parte inferior del panel.
   ══════════════════════════════════════════════════════════════ */

/* Contenedor global — fijo, apilado desde abajo */
#task-alerts {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
    display: flex;
    flex-direction: column-reverse;   /* las nuevas aparecen arriba */
    gap: .75rem;
    max-width: 420px;
    width: calc(100vw - 3rem);
    pointer-events: none;             /* no bloquea el fondo */
}

/* Tarjeta individual */
.task-alert {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-primary);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgb(0 0 0 / .12);
    padding: 1rem 1rem 1rem 1.1rem;
    pointer-events: all;
    animation: ta-slide-in .25s ease;
    transition: opacity .3s, transform .3s;
}

@keyframes ta-slide-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Estados — color del borde izquierdo */
.task-alert[data-status="queued"]     { border-left-color: var(--color-muted); }
.task-alert[data-status="running"]    { border-left-color: var(--color-primary); }
.task-alert[data-status="done"]       { border-left-color: var(--color-success); }
.task-alert[data-status="failed"]     { border-left-color: var(--color-error); }
.task-alert[data-status="cancelled"]  { border-left-color: var(--color-warning); }

/* Cabecera */
.task-alert__head {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
}
.task-alert__icon   { font-size: 1.1rem; flex-shrink: 0; margin-top: .05rem; }
.task-alert__info   { flex: 1; min-width: 0; }
.task-alert__title  {
    font-weight: 600;
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--color-text);
}
.task-alert__status {
    font-size: .78rem;
    color: var(--color-muted);
    margin-top: .1rem;
}
.task-alert__status.is-error  { color: var(--color-error); }
.task-alert__status.is-done   { color: var(--color-success); }

/* Botón cerrar */
.task-alert__close {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-muted);
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 0 0 .5rem;
    opacity: .6;
    transition: opacity .15s;
}
.task-alert__close:hover { opacity: 1; }

/* Barra de progreso */
.task-alert__progress {
    margin-top: .75rem;
    height: 4px;
    background: var(--color-border);
    border-radius: 99px;
    overflow: hidden;
}
.task-alert__bar {
    height: 100%;
    border-radius: 99px;
    background: var(--color-primary);
    transition: width .4s ease;
}
.task-alert[data-status="done"]   .task-alert__bar { background: var(--color-success); }
.task-alert[data-status="failed"] .task-alert__bar { background: var(--color-error); }

/* Spinner en running */
.task-alert__spin {
    display: none;
    width: 12px; height: 12px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
    align-self: center;
}
.task-alert[data-status="running"]  .task-alert__spin,
.task-alert[data-status="queued"]   .task-alert__spin { display: block; }

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

/* Ocultar progreso cuando está done / failed y sin error relevante */
.task-alert[data-status="done"]     .task-alert__progress,
.task-alert[data-status="cancelled"] .task-alert__progress { opacity: .3; }

/* Salida */
.task-alert.is-dismissing {
    opacity: 0;
    transform: translateX(16px);
}

/* ── Notification badge ─────────────────────────────────────────────────────── */
.notif-link { position: relative; }
.notif-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--color-error);
    color: #fff;
    font-size: .68rem;
    font-weight: 700;
    margin-left: .4rem;
    vertical-align: middle;
    line-height: 1;
}
