:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --panel-3: #eef1f5;
  --input-bg: #ffffff;
  --row-hover: #f9fbfd;
  --accent-soft: #e8effd;
  --border: #e2e6ec;
  --text: #1c2430;
  --muted: #6b7684;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #16a34a;
  --danger: #dc2626;
  --amber: #d97706;
  --cyan: #0891b2;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 20px 60px rgba(16,24,40,.25);
}

/* Modo oscuro (se activa con data-theme="dark" en <html>). */
:root[data-theme="dark"] {
  --bg: #0f141b;
  --panel: #161d27;
  --panel-2: #1e2733;
  --panel-3: #222c39;
  --input-bg: #111823;
  --row-hover: #1b2430;
  --accent-soft: #1e2c46;
  --border: #2b3542;
  --text: #e6ebf2;
  --muted: #9aa7b6;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --shadow: 0 1px 3px rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.3);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.55);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.muted { color: var(--muted); }
.error { color: var(--danger); }
.cargando { color: var(--muted); padding: 24px; }

/* ---------- Botones y controles ---------- */
button {
  padding: 9px 16px; border: 1px solid var(--border); background: var(--panel);
  border-radius: 8px; font-size: 14px; cursor: pointer; color: var(--text);
}
button:hover { background: var(--panel-2); }
button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.primary:hover { background: var(--primary-dark); }
button.mini { padding: 5px 10px; font-size: 13px; }
button.peligro { color: var(--danger); border-color: #f3c9c9; }
button.peligro:hover { background: #fdf0f0; }
button.bloque { width: 100%; padding: 12px; font-size: 15px; }
input, select, textarea {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; color: var(--text); font-family: inherit; background: var(--input-bg);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ---------- Login ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; background: var(--bg); }
.auth-card { position: relative; background: var(--panel); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px; width: min(400px, 92vw); }
.tema-login { position: absolute; top: 14px; right: 14px; }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand h1 { margin: 8px 0 2px; font-size: 22px; letter-spacing: .04em; }
.logo { width: 48px; height: 48px; border-radius: 12px; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 24px; margin: 0 auto; }
.tabs-auth { display: flex; gap: 6px; background: var(--panel-3); padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.tab-auth { flex: 1; border: none; background: transparent; padding: 8px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.tab-auth.activa { background: var(--panel); box-shadow: var(--shadow); color: var(--primary); }
.auth-titulo { text-align: center; font-size: 15px; margin: 0 0 16px; color: var(--muted); font-weight: 600; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }

/* ---------- Topbar / nav ---------- */
.topbar { display: flex; align-items: center; gap: 20px; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .03em; }
.brand .logo { width: 30px; height: 30px; font-size: 16px; border-radius: 8px; }
.nav { display: flex; gap: 4px; }
.nav-item { border: none; background: transparent; padding: 8px 14px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.nav-item:hover { background: var(--panel-2); }
.nav-item.activa { background: var(--accent-soft); color: var(--primary); }
.usuario { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 14px; }

main#view { max-width: 1320px; margin: 22px auto; padding: 0 16px; }

/* ---------- Cabeceras de pagina / toolbars ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.page-head h2 { margin: 0; font-size: 20px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar #q { flex: 1; min-width: 220px; }
.contador { color: var(--muted); font-size: 13px; margin-left: auto; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.tabla-wrap { 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); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--row-hover); }
.acciones-fila { display: flex; gap: 6px; }
.vacio { text-align: center; color: var(--muted); padding: 24px; }

/* ---------- Pills / etiquetas ---------- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.verde { background: #dcfce7; color: #15803d; }
.pill.ambar { background: #fef3c7; color: #b45309; }
.pill.gris  { background: #eef1f5; color: #64748b; }
.pill.azul  { background: #e0ecfe; color: #1d4ed8; }
.pill.cyan  { background: #cffafe; color: #0e7490; }
.dot-color { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }

/* ---------- Salas (vista despacho) ---------- */
.salas-tools { display: flex; align-items: flex-end; gap: 14px; }
.dia-lbl { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }

.salas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.room-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  overflow: hidden; display: flex; flex-direction: column; }
.room-card.inactiva { opacity: .55; }

.room-head { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-top: 4px solid var(--rc); }
.room-title { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.room-title h3 { margin: 0; font-size: 16px; }
.room-occ { font-size: 20px; font-weight: 800; color: var(--muted); white-space: nowrap; text-align: right; line-height: 1; }
.room-occ span { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.room-occ.hay { color: var(--ok); }

/* Office floor plan */
.office { background: var(--panel-2); margin: 0 16px 14px; border-radius: 12px; border: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.office.big { padding: 30px 20px; gap: 22px; margin: 14px 0; }
.chair-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; min-height: 44px; }
.chair-row.reversed .chair { flex-direction: column-reverse; }
.desk { width: 70%; min-width: 120px; min-height: 46px; border-radius: 8px;
  background: linear-gradient(180deg, #d7c3a8, #c9b191); border: 1px solid rgba(0,0,0,.12);
  display: flex; align-items: center; justify-content: center;
  color: rgba(60,40,20,.7); font-size: 11px; font-weight: 700; letter-spacing: .12em; }
.office.big .desk { min-height: 70px; }
:root[data-theme="dark"] .desk { background: linear-gradient(180deg, #6b5842, #55452f); color: rgba(255,255,255,.55); border-color: rgba(0,0,0,.4); }

.chair { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 58px; }
.chair-name { font-size: 11px; font-weight: 600; max-width: 66px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; color: var(--text); min-height: 14px; text-align: center; }
.seat { width: 30px; height: 28px; border-radius: 9px 9px 7px 7px; border: 2px solid var(--border);
  background: var(--panel); position: relative; }
.seat::after { content: ''; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  width: 22px; height: 5px; border-radius: 3px; background: inherit; border: inherit; border-top: none; opacity: .8; }
.office.big .seat { width: 40px; height: 36px; }
.chair.occupied .chair-name { font-weight: 700; }

.room-foot { display: flex; align-items: center; gap: 6px; padding: 10px 16px 14px; }
.room-foot .spacer { flex: 1; }

.room-detail h3 { display: flex; align-items: center; gap: 10px; }
.occ-h { margin: 14px 0 8px; font-size: 14px; }
.occ-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.occ-list li { display: flex; align-items: center; gap: 8px; font-size: 14px; }

/* ---------- Modales ---------- */
dialog { border: none; border-radius: 14px; padding: 0; box-shadow: var(--shadow-lg); width: min(760px, 94vw); }
dialog::backdrop { background: rgba(16,24,40,.45); }
.form-modal { padding: 22px; }
.form-modal h3 { margin: 0 0 16px; font-size: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form-modal label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.form-modal label.full { grid-column: 1 / -1; }
.form-modal label.check { flex-direction: row; align-items: center; gap: 8px; margin-top: 8px; }
.acciones { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- Toasts ---------- */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px;
  opacity: 0; transition: all .3s; z-index: 100; box-shadow: var(--shadow-lg); }
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

/* ---------- Calendario (Gantt) ---------- */
.cal-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.seg { display: flex; background: var(--panel-3); border-radius: 9px; padding: 3px; }
.seg button { border: none; background: transparent; padding: 6px 14px; border-radius: 7px; font-weight: 600; color: var(--muted); }
.seg button.activa { background: var(--panel); color: var(--primary); box-shadow: var(--shadow); }
.cal-nav { display: flex; gap: 4px; }
.periodo { font-size: 15px; }
.cal-ayuda { margin-top: 8px; font-size: 13px; }
.cal-wrap { padding: 0; overflow: hidden; }

.gantt { display: flex; }
.gantt-side { flex: 0 0 auto; border-right: 2px solid var(--border); background: var(--panel-2); z-index: 2; }
.gantt-corner { height: 56px; display: flex; align-items: center; padding: 0 14px; font-size: 12px;
  text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--border); }
.gantt-salalbl { display: flex; align-items: center; gap: 6px; padding: 0 14px; font-size: 14px; font-weight: 600;
  border-bottom: 1px solid var(--border); white-space: nowrap; min-width: 170px; }
.gantt-scroll { overflow-x: auto; flex: 1; }
.gantt-tl { position: relative; }
.gantt-head { display: flex; height: 56px; border-bottom: 1px solid var(--border); }
.th-dia { display: flex; flex-direction: column; align-items: center; justify-content: center; border-right: 1px solid var(--border); flex: 0 0 auto; }
.th-dia.finde { background: var(--panel-2); }
.th-dow { font-size: 12px; color: var(--muted); }
.th-num { font-weight: 700; font-size: 17px; }
.th-mes { display: flex; align-items: center; padding: 0 10px; border-right: 1px solid var(--border); flex: 0 0 auto;
  font-weight: 600; font-size: 13px; color: var(--muted); text-transform: uppercase; }
.gantt-body { position: relative; }
.gantt-fila { position: relative; border-bottom: 1px solid var(--border); }
.hoy-line { position: absolute; top: 0; bottom: 0; width: 2px; background: #ef4444; z-index: 1; opacity: .6; }
.barra { position: absolute; height: 24px; border-radius: 6px; color: #fff; font-size: 13px; line-height: 24px;
  padding: 0 9px; overflow: hidden; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.barra span { white-space: nowrap; }
.barra:hover { filter: brightness(1.08); outline: 2px solid rgba(255,255,255,.6); }
.barra.anulada { opacity: .45; text-decoration: line-through; }

/* ---------- Logo enlazable ---------- */
a.brand { text-decoration: none; color: inherit; cursor: pointer; }
a.brand:hover { opacity: .85; }
.brand .logo-img { height: 34px; width: auto; display: block; }
.auth-logo { height: 56px; width: auto; margin: 0 auto 8px; display: block; }
/* Cambia el logo (color / blanco) según el tema. */
.logo-dark { display: none; }
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }

/* ---------- Reservas: botón de filtros, panel lateral y paginación ---------- */
.btn-filtros { display: inline-flex; align-items: center; gap: 6px; }
.badge { background: var(--primary); color: #fff; border-radius: 999px; font-size: 11px; min-width: 18px;
  height: 18px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; }
.badge[hidden] { display: none; }

.drawer-overlay { position: fixed; inset: 0; background: rgba(16,24,40,.4); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(340px, 92vw); background: var(--panel);
  border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); z-index: 41; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .2s ease; }
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { margin: 0; font-size: 17px; }
.drawer-body { padding: 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.drawer-foot { padding: 14px 16px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: space-between; }
.filtro-grupo { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 0; }
.filtro-grupo legend { font-size: 13px; color: var(--muted); padding: 0 6px; }
.chk-list { display: flex; flex-direction: column; gap: 7px; max-height: 240px; overflow-y: auto; }
.chk-list .check { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.filtro-grupo > label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; }
.pager-info { font-size: 14px; color: var(--muted); }
.pager:empty { display: none; }

/* ---------- Cabeceras ordenables ---------- */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary); }
th[data-dir]::after { content: ' ▲'; font-size: 10px; color: var(--primary); }
th[data-dir="desc"]::after { content: ' ▼'; }

/* ---------- Filtros multi-selección ---------- */
.multi-lbl { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); }
.multi-lbl select[multiple] { min-width: 140px; }
select[multiple] { padding: 4px; height: auto; }
.form-modal select[multiple] { min-height: 120px; }

/* ---------- Usuarios: permisos ---------- */
.permisos-box { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-top: 10px; }
.permisos-box legend { font-size: 13px; color: var(--muted); padding: 0 6px; }
.permisos-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.permisos-grid.bloqueado { opacity: .5; pointer-events: none; }
.mini-nota { font-size: 12px; margin: 10px 0 0; }
.permisos-celda { white-space: normal; line-height: 1.9; }

@media (max-width: 700px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .nav-item { padding: 8px 10px; }
  .permisos-grid { grid-template-columns: 1fr; }
}
