/* AlertBot — Panel de notificaciones v3 */
:root {
    --bg: #f1f5f9;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-active: #3b82f6;
    --card-bg: #fff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --ok: #10b981;
    --ok-bg: #ecfdf5;
    --warn: #f59e0b;
    --warn-bg: #fffbeb;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-bg: #eff6ff;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    --sidebar-w: 240px;
    --transition: 0.2s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

/* ===== Login ===== */
body.login-body {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}

.login-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    margin: 1rem;
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255,255,255,0.05);
}

.login-card h1 {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.15rem;
    color: var(--text);
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

.login-error {
    background: var(--danger-bg);
    color: #991b1b;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    border: 1px solid #fecaca;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid rgba(255,255,255,0.06);
}

.sidebar-header {
    padding: 1.25rem 1.15rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #fff;
}

.sidebar-logo svg {
    color: var(--primary);
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-size: 1.1rem;
    color: #fff;
    font-weight: 700;
    line-height: 1.2;
}

.sidebar-header .subtitle {
    font-size: 0.7rem;
    color: var(--sidebar-text);
    letter-spacing: 0.02em;
}

.sidebar ul {
    list-style: none;
    padding: 0.75rem 0.6rem;
    flex: 1;
    overflow-y: auto;
}

.sidebar ul li a {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.6rem 0.85rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.87rem;
    font-weight: 450;
    border-radius: 8px;
    transition: all var(--transition);
    margin-bottom: 2px;
}

.sidebar ul li a svg {
    flex-shrink: 0;
    opacity: 0.6;
    transition: opacity var(--transition);
}

.sidebar ul li a:hover {
    background: var(--sidebar-hover);
    color: #e2e8f0;
}

.sidebar ul li a:hover svg {
    opacity: 0.9;
}

.sidebar ul li a.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(59,130,246,0.4);
}

.sidebar ul li a.active svg {
    opacity: 1;
}

.sidebar-section {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.25);
    padding: 1.1rem 0.85rem 0.4rem;
    font-weight: 600;
}

.sidebar-footer {
    padding: 0.85rem 1rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--sidebar-text);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.sidebar-user span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-footer a {
    color: #f87171;
    text-decoration: none;
    font-size: 0.78rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: color var(--transition);
}

.sidebar-footer a:hover {
    color: #fca5a5;
}

/* Sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.open {
    display: block;
}

/* ===== Hamburger ===== */
.hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.4rem;
    margin-right: 0.75rem;
    border-radius: 8px;
    line-height: 1;
    flex-shrink: 0;
    transition: all var(--transition);
}

.hamburger:hover {
    background: var(--bg);
    color: var(--text);
}

/* ===== Main content ===== */
.content {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
}

.topbar {
    background: var(--card-bg);
    padding: 0.85rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar h1 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page-content {
    padding: 1.5rem;
    max-width: 1400px;
}

/* ===== Stats grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), transform var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.stat-card.card-ok {
    border-left: 4px solid var(--ok);
    background: linear-gradient(135deg, var(--ok-bg) 0%, var(--card-bg) 100%);
}

.stat-card.card-warn {
    border-left: 4px solid var(--warn);
    background: linear-gradient(135deg, var(--warn-bg) 0%, var(--card-bg) 100%);
}

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.2rem;
    color: var(--text);
}

.stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* ===== Cards ===== */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.35rem;
    box-shadow: var(--shadow-sm);
}

.card h3 {
    font-size: 0.95rem;
    margin-bottom: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

/* ===== Section headers ===== */
h2 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 1rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.section-header h2 {
    margin-bottom: 0;
}

/* ===== Tables ===== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    margin-bottom: 1.75rem;
    box-shadow: var(--shadow-sm);
    background: var(--card-bg);
}

.table-responsive table {
    border: none;
    border-radius: 0;
    margin-bottom: 0;
    box-shadow: none;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

thead th {
    background: #f8fafc;
    padding: 0.7rem 0.9rem;
    text-align: left;
    font-size: 0.72rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    font-weight: 600;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.87rem;
    color: var(--text-secondary);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: background var(--transition);
}

tbody tr:hover {
    background: #f8fafc;
}

tbody tr.row-pending {
    background: var(--warn-bg);
}

tbody tr.row-pending:hover {
    background: #fef3c7;
}

td.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 2.5rem;
    font-size: 0.9rem;
}

td.td-truncate {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

td.td-nowrap {
    white-space: nowrap;
}

/* ===== Expandable rows ===== */
.expandable-row {
    cursor: pointer;
}

.expandable-row:hover {
    background: var(--primary-bg) !important;
}

.detail-row {
    display: none;
}

.detail-row.open {
    display: table-row;
}

.detail-row td {
    background: #f8fafc;
    border-left: 3px solid var(--primary);
}

.detail-content {
    padding: 0.6rem 0.5rem;
    font-size: 0.84rem;
    line-height: 1.7;
}

.detail-content div {
    margin-bottom: 0.15rem;
}

.detail-content strong {
    color: var(--text);
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.badge-ok {
    background: #dcfce7;
    color: #166534;
}

.badge-warn {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.84rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    font-family: inherit;
}

.btn:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-sm {
    padding: 0.32rem 0.7rem;
    font-size: 0.78rem;
    border-radius: 6px;
}

.btn-secondary {
    background: #64748b;
}

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

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

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

.btn-ok {
    background: var(--ok);
}

.btn-ok:hover {
    background: #059669;
}

/* ===== Toolbar & Inline forms ===== */
.toolbar {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.15rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.inline-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.inline-form input,
.inline-form select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--card-bg);
}

.inline-form input:focus,
.inline-form select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

/* ===== Forms (CEJ style) ===== */
.form-add {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.15rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.form-add h3 {
    margin-bottom: 0.85rem;
    font-size: 0.95rem;
    font-weight: 600;
}

.form-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: end;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
}

.form-group label {
    font-size: 0.76rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.input, select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    min-width: 0;
    background: var(--card-bg);
}

.input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.form-inline {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ===== Status text ===== */
.status-ok {
    color: var(--ok);
    font-weight: 600;
}

.status-err {
    color: var(--danger);
    font-weight: 600;
}

/* ===== Test result ===== */
.test-result {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-top: 1rem;
    font-size: 0.88rem;
}

/* ===== WA actions ===== */
.wa-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* ===== Inline editing ===== */
.cell-edit {
    padding: 0.35rem 0.55rem;
    border: 2px solid var(--primary);
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: inherit;
    width: 100%;
    max-width: 250px;
    outline: none;
    min-width: 0;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.acciones-cell {
    white-space: nowrap;
    display: flex;
    gap: 0.35rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ===== Toast notifications ===== */
#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: min(400px, calc(100vw - 2rem));
}

.toast {
    background: var(--sidebar-bg);
    color: #fff;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    word-break: break-word;
    font-weight: 500;
}

.toast.toast-error {
    background: var(--danger);
}

.toast.toast-ok {
    background: #059669;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== Responsive: Tablet (<=768px) ===== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .hamburger {
        display: flex;
    }

    .content {
        margin-left: 0;
    }

    .page-content {
        padding: 1rem;
    }

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

    .form-row {
        flex-direction: column;
    }

    .form-row .form-group {
        width: 100%;
    }

    .form-row .form-group input,
    .form-row .form-group select {
        width: 100%;
    }

    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }

    .inline-form input,
    .inline-form select {
        width: 100%;
    }

    .cell-edit {
        max-width: 100%;
    }

    .acciones-cell {
        white-space: normal;
    }
}

/* ===== Responsive: Mobile (<=540px) ===== */
@media (max-width: 540px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .login-card {
        padding: 1.5rem 1.25rem;
    }

    .topbar {
        padding: 0.65rem 0.85rem;
    }

    .topbar h1 {
        font-size: 1rem;
    }

    .page-content {
        padding: 0.75rem;
    }

    .stat-card {
        padding: 0.9rem;
    }

    .stat-value {
        font-size: 1.4rem;
    }

    .form-add {
        padding: 0.85rem;
    }

    .toolbar {
        padding: 0.85rem;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }
}
