:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --border: #e3e8f0;
    --text: #1c2434;
    --muted: #6b7690;
    --brand: #3b62d9;
    --brand-dark: #2c4bb0;
    --ok: #1f9d6b;
    --ok-soft: #e6f7f0;
    --warn: #d9822b;
    --night: #4b3fae;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 8px 24px rgba(20, 30, 60, .06);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    overflow-x: hidden;   /* ningún bloque debe provocar scroll lateral */
    min-width: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--brand); }

/* ---------- Barra superior ---------- */

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px 20px;
    min-height: 62px;
    flex-wrap: wrap;
    padding: 8px 0;
}

.brand {
    text-decoration: none;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.brand-nombre {
    font-weight: 800;
    font-size: 22px;
    letter-spacing: -.02em;
    color: var(--brand);
}

.brand-sub {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    padding-left: 12px;
    border-left: 1px solid var(--border);
    letter-spacing: -.01em;
}

.topbar nav {
    display: flex;
    gap: 6px 14px;
    margin-left: auto;
    align-items: center;
    flex-wrap: wrap;
}

.topbar nav a {
    text-decoration: none;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 8px;
}

.topbar nav a:hover { background: var(--bg); color: var(--text); }
.topbar nav a.active { color: var(--brand); background: #eef2fd; }

.usuario { font-size: 13px; color: var(--muted); }

/* Selector de idioma, junto al nombre del usuario */
.lang-switch {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.lang-switch a {
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    border-radius: 0;
    letter-spacing: .03em;
}

.lang-switch a.on { background: var(--brand); color: #fff; }
.lang-switch a.on:hover { background: var(--brand-dark); color: #fff; }

/* ---------- Estructura ---------- */

.wrap { max-width: 1100px; margin: 32px auto 64px; padding: 0 20px; }
.wrap-narrow { max-width: 460px; margin: 48px auto; padding: 0 20px; }


h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

/* ---------- Formularios ---------- */

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }

input[type=text], input[type=password], select {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    font-size: 16px;   /* 16px evita el zoom automático en iOS */
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(59, 98, 217, .15);
}

.field { margin-bottom: 16px; }
.ayuda { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
input:invalid:not(:placeholder-shown) { border-color: #d9534f; }
.row { display: flex; gap: 14px; }
.row > * { flex: 1; }

.btn {
    display: inline-block;
    background: var(--brand);
    color: #fff;
    border: 0;
    border-radius: 9px;
    padding: 11px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    text-align: center;
}

.btn:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 8px 12px; font-size: 13px; }

/* Botón de eliminar: una X roja junto a la acción de promover */
.btn-x {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid #f0c2c6;
    border-radius: 8px;
    background: #fff;
    color: #c0392b;
    font-size: 19px;
    line-height: 1;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-x:hover { background: #fdeced; border-color: #e6a2a8; color: #a12630; }
.btn-x:focus-visible { outline: 2px solid #c0392b; outline-offset: 2px; }

.acciones-fila { display: flex; gap: 8px; flex-wrap: nowrap; align-items: center; }
.btn-block { width: 100%; }

/* ---------- Avisos y etiquetas ---------- */

.alert { padding: 12px 14px; border-radius: 9px; font-size: 14px; margin-bottom: 18px; }
.alert-error { background: #fdeced; color: #a12630; border: 1px solid #f6ccd0; }
.alert-ok { background: var(--ok-soft); color: #16704d; border: 1px solid #c4ebda; }
.alert-info { background: #eef2fd; color: #2c4bb0; border: 1px solid #d3ddf8; }

.pill {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 999px;
    white-space: nowrap;
}

.pill-diurno { background: #fff4e3; color: var(--warn); }
.pill-nocturno { background: #eeecfb; color: var(--night); }
.pill-admin { background: #eef2fd; color: var(--brand); }
.pill-neutro { background: #eef0f5; color: var(--muted); }

/* ---------- Rejilla de disponibilidad ---------- */

.dias {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.dia {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    text-align: center;
    background: #fff;
    transition: border-color .12s, background .12s;
}

.dia-cabecera { display: block; cursor: pointer; margin: 0; }
.dia.bloqueado .dia-cabecera { cursor: default; }

.dia input[type=checkbox] { position: absolute; opacity: 0; pointer-events: none; }
.dia .nombre { display: block; font-size: 13px; font-weight: 600; }
.dia .fecha { display: block; font-size: 12px; color: var(--muted); }
.dia .estado { display: block; margin-top: 8px; font-size: 12px; font-weight: 600; color: var(--muted); }

.dia.activo { border-color: var(--ok); background: var(--ok-soft); }
.dia.activo .estado { color: var(--ok); }

/* Selección de horas por día */
.dia-horas {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
    display: grid;
    gap: 6px;
    text-align: left;
}

.dia-horas label { margin: 0; display: flex; align-items: center; gap: 6px; justify-content: space-between; }

.dia-horas .hora-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    font-weight: 600;
}

.dia-horas select {
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 6px 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    width: auto;
    min-width: 84px;
}

.dia-horas select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(59, 98, 217, .15);
}

.dia-horas select:disabled { background: #f7f8fb; color: var(--muted); }

/* Un día ya enviado y no disponible no necesita mostrar horas */
.dia.bloqueado:not(.activo) .dia-horas { display: none; }

.dia .duracion {
    display: block;
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
    min-height: 15px;
    text-align: center;
}

.dia:not(.activo) .dia-horas { opacity: .45; }

.horas-celda { white-space: nowrap; }
.horas-celda .muted { margin-left: 6px; }

/* ---------- Calendario del admin ---------- */

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; }

.cal-dia {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    padding: 14px 12px;
    text-align: center;
}

.cal-dia .nombre { font-size: 13px; font-weight: 600; }
.cal-dia .fecha { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.cal-dia .total { font-size: 30px; font-weight: 700; line-height: 1.1; }
.cal-dia .total.cero { color: #c3cad8; }
.cal-dia .desglose { font-size: 12px; color: var(--muted); margin-top: 6px; }
.cal-dia a { display: inline-block; margin-top: 10px; font-size: 12px; }

/* Un bloque independiente por turno en el panel de administración */
.bloque-turno { border-top: 4px solid var(--border); }
.bloque-diurno { border-top-color: var(--warn); }
.bloque-nocturno { border-top-color: var(--night); }

.bloque-diurno .cal-dia .total { color: var(--warn); }
.bloque-nocturno .cal-dia .total { color: var(--night); }
.bloque-turno .cal-dia .total.cero { color: #c3cad8; }

.detalle {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.detalle-titulo { font-size: 15px; margin: 0; }

/* ---------- Tablas ---------- */

.tabla-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.toolbar .spacer { flex: 1; }

.muted { color: var(--muted); font-size: 13px; }

/* ---------- Móvil ---------- */

@media (max-width: 900px) {
    .cal { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 620px) {
    .wrap { margin: 20px auto 48px; }
    .card { padding: 18px 16px; }
    h1 { font-size: 21px; }

    .topbar-inner { min-height: 0; }
    .topbar nav { margin-left: 0; width: 100%; justify-content: flex-start; }
    .topbar nav a { padding: 6px 8px; }
    .usuario { order: 10; }

    .brand { gap: 9px; }
    .brand-nombre { font-size: 19px; }
    .brand-sub { font-size: 13px; padding-left: 9px; }

    .dias { grid-template-columns: 1fr; }
    .cal { grid-template-columns: repeat(2, 1fr); }
    .row { flex-direction: column; gap: 0; }

    /* En el móvil cada día ocupa una fila completa, con las horas en línea */
    .dia { display: grid; grid-template-columns: 1fr auto; gap: 10px; text-align: left; align-items: center; }
    .dia .estado { margin-top: 4px; }
    .dia-horas { margin-top: 0; padding-top: 0; border-top: 0; border-left: 1px dashed var(--border); padding-left: 12px; }
    .dia .duracion { text-align: right; }
    .horas-celda { white-space: normal; }
    .toolbar .btn { width: 100%; }
    .btn-block-sm { width: 100%; }

    /* Las tablas se apilan en tarjetas para no obligar a hacer scroll lateral */
    .tabla-scroll table thead { display: none; }
    .tabla-scroll table, .tabla-scroll tbody, .tabla-scroll tr, .tabla-scroll td { display: block; width: 100%; }
    .tabla-scroll tr {
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 6px 4px;
        margin-bottom: 10px;
    }
    .tabla-scroll td {
        border: 0;
        padding: 6px 10px;
        display: flex;
        justify-content: space-between;
        gap: 12px;
        align-items: center;
    }
    .tabla-scroll td::before {
        content: attr(data-th);
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--muted);
        font-weight: 600;
    }
    .tabla-scroll td:not([data-th]) { justify-content: flex-start; }
    .tabla-scroll td .btn { width: 100%; }
    /* La X mantiene su tamaño; el botón de rol ocupa el resto de la fila */
    .acciones-fila { width: 100%; }
    .acciones-fila form:first-child { flex: 1; min-width: 120px; }
    .acciones-fila .btn-x { width: 36px; height: 36px; }
}
