:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --text: #1a1a1a;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --border: #e5e7eb;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem;
}

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
}

.brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
}

nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.muted {
    color: var(--muted);
    font-size: 0.9rem;
}

.muted.small {
    font-size: 0.8rem;
    margin: 0 0 0.5rem 0;
}

h1 { font-size: 1.5rem; margin-top: 0; margin-bottom: 1rem; }
h2 { font-size: 1.15rem; margin-top: 0; margin-bottom: 0.75rem; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border-color: #fecaca;
}

.auth-card {
    max-width: 420px;
    margin: 4rem auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
}

.auth-card h1 { margin-bottom: 0.25rem; }

form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

label {
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
    font-weight: 500;
    gap: 0.25rem;
}

input, select, textarea {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    background: white;
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

.btn {
    padding: 0.55rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font: inherit;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    transition: background-color 0.15s ease;
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled {
    background: #cbd5e1;
    color: var(--muted);
    cursor: not-allowed;
}

.btn-secondary {
    background: white;
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { background: #f9fafb; }

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

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font: inherit;
    padding: 0;
}
.btn-link:hover { text-decoration: underline; }

.branch-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}
.branch-row select { flex: 1; min-width: 200px; }

.classes-header {
    margin: 0 0 0.75rem 0;
}

/* ============================================================ */
/* Week toggle — "Esta semana" / "Próxima semana"               */
/* ============================================================ */
.week-toggle {
    display: inline-flex;
    gap: 0;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
    background: white;
}
.week-btn {
    padding: 0.5rem 1.1rem;
    background: white;
    color: var(--text);
    border: none;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
    white-space: nowrap;
}
.week-btn:not(.active):hover {
    background: #eef2f7;
}
.week-btn.active {
    background: var(--primary);
    color: white;
    font-weight: 600;
}
.week-btn + .week-btn {
    border-left: 1px solid var(--border);
}
.week-btn.active + .week-btn,
.week-btn.active { border-left-color: var(--primary); }

.filters {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: end;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: #fafbfc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.filter {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

.filter select {
    min-width: 140px;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--text);
}

#clear-filters {
    align-self: end;
    margin-bottom: 0.45rem;
    white-space: nowrap;
}

.htmx-indicator {
    opacity: 0;
    transition: opacity 0.2s ease;
}
.htmx-indicator.htmx-request {
    opacity: 1;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
}

.class-card, .booking-card, .run-card {
    background: #fafbfc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.class-card.status-full { opacity: 0.7; }

.class-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.class-name {
    font-weight: 700;
    font-size: 1.05rem;
}

.class-meta {
    font-size: 0.85rem;
    color: var(--muted);
}

.class-meta > div + div {
    margin-top: 0.15rem;
}

.status-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.status-badge.status-available, .status-badge.status-done {
    background: #dcfce7;
    color: var(--success);
}
.status-badge.status-full,
.status-badge.status-failed,
.status-badge.status-cancelled,
.status-badge.status-interrupted {
    background: #fee2e2;
    color: var(--danger);
}
.status-badge.status-running, .status-badge.status-pending {
    background: #fef3c7;
    color: var(--warning);
}
.status-badge.status-registered {
    background: #dbeafe;
    color: #1e40af;
}
.status-badge.status-unknown {
    background: #f3f4f6;
    color: var(--muted);
}
.status-badge.status-bot-scheduled {
    background: #ede9fe;
    color: #5b21b6;
}
.class-card.status-bot-scheduled {
    background: #faf5ff;
}

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

.focus-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.5rem;
}

.focus-item {
    background: #fafbfc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    text-align: center;
}

.focus-today {
    background: #dbeafe;
    border-color: #93c5fd;
    box-shadow: 0 0 0 1px #93c5fd;
}

.focus-day {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.focus-today .focus-day {
    color: #1e40af;
}

.focus-name {
    font-size: 0.9rem;
    color: var(--text);
    line-height: 1.3;
}

/* ----- Admin panel ----- */
.inline-form {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}
.inline-form input[type="email"] {
    flex: 1 1 220px;
    min-width: 180px;
}
.inline-form input[type="text"] {
    flex: 2 1 280px;
    min-width: 200px;
}

.emails-table {
    width: 100%;
    border-collapse: collapse;
}
.emails-table th,
.emails-table td {
    text-align: left;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.emails-table th {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.06em;
    font-weight: 700;
    border-bottom: 2px solid var(--border);
}
.emails-table tr:last-child td {
    border-bottom: none;
}
.emails-table tr.is-disabled td {
    background: #fafbfc;
    color: var(--muted);
}
.emails-table tr.is-disabled .email-cell {
    text-decoration: line-through;
    text-decoration-color: var(--danger);
    text-decoration-thickness: 1px;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.4;
    vertical-align: middle;
}
.badge-enabled {
    background: #d1fae5;
    color: #065f46;
}
.badge-disabled {
    background: #fee2e2;
    color: #991b1b;
}
.badge-self {
    background: #dbeafe;
    color: #1e3a8a;
    margin-left: 0.4rem;
}
.emails-table .email-cell {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9rem;
}
.emails-table .actions {
    text-align: right;
    width: 1%;
    white-space: nowrap;
}

.btn-link.danger {
    color: var(--danger);
}
.btn-link.danger:hover {
    text-decoration: underline;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 1.5rem;
    font-style: italic;
}

.error {
    color: var(--danger);
    padding: 1rem;
    text-align: center;
}

.log {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8rem;
    line-height: 1.45;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    padding: 0.75rem 1rem;
    background: var(--text);
    color: white;
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.2s ease;
    pointer-events: auto;
    max-width: 360px;
}

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

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