:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #5c6b7a;
  --line: #d7dee8;
  --blue: #1f4e79;
  --blue-2: #2d6da8;
  --red: #c62828;
  --red-bg: #fdecea;
  --amber: #b26a00;
  --amber-bg: #fff6e5;
  --ok: #1b7f4d;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }

.topbar {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: center;
  justify-content: space-between;
  background: var(--blue); color: #fff;
  padding: 0.7rem 1.1rem;
}
.brand h1 { margin: 0; font-size: 1.15rem; font-weight: 650; }
.brand .sub { font-size: 0.8rem; opacity: 0.85; }
.controls { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: end; }
.controls label { display: flex; flex-direction: column; font-size: 0.72rem; gap: 0.15rem; opacity: 0.95; }
.controls input, .controls select {
  border: none; border-radius: 6px; padding: 0.4rem 0.5rem;
  font-size: 0.9rem; color: var(--ink); background: #fff;
}
.controls input[type="number"] { width: 7.2rem; }
button {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 7px; padding: 0.45rem 0.8rem; cursor: pointer;
  font-size: 0.88rem;
}
button:hover { border-color: var(--blue-2); }
button.primary {
  background: #ffd54f; border-color: #f0c000; color: #3a2f00; font-weight: 650;
}
button.primary:hover { background: #ffde6b; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

.tabs {
  display: flex; gap: 0.3rem; padding: 0.5rem 1rem 0;
  background: var(--bg);
}
.tab {
  background: #e4eaf2; border: 1px solid var(--line); border-bottom: none;
  border-radius: 8px 8px 0 0; padding: 0.45rem 1rem;
}
.tab.active { background: var(--panel); font-weight: 650; }
.badge {
  background: var(--red); color: #fff; border-radius: 999px;
  font-size: 0.7rem; padding: 0.05rem 0.4rem; margin-left: 0.25rem;
}
.badge.zero { background: #90a4ae; }

main { padding: 0 1rem 2rem; }
.tab-panel { display: none; }
.tab-panel.active { display: flex; gap: 1rem; padding-top: 0.6rem; }

.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.7rem; max-height: calc(100vh - 140px);
  overflow: auto;
}
.filter {
  width: 100%; padding: 0.45rem 0.55rem; border: 1px solid var(--line);
  border-radius: 7px; margin-bottom: 0.6rem; font-size: 0.9rem;
}
.teacher-list { display: flex; flex-direction: column; gap: 0.25rem; }
.teacher-item {
  text-align: left; border: 1px solid transparent; background: #f7f9fc;
  border-radius: 7px; padding: 0.45rem 0.55rem; cursor: pointer; font-size: 0.86rem;
}
.teacher-item:hover { background: #eef3fa; }
.teacher-item.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.teacher-item .cat { display: block; font-size: 0.72rem; opacity: 0.75; }
.teacher-item .warn-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--red); margin-left: 0.35rem; vertical-align: middle;
}

.content {
  flex: 1; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem; min-width: 0;
}
.content.wide { max-width: 1200px; }
.pane-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 0.7rem;
}
.pane-head h2 { margin: 0 0 0.2rem; font-size: 1.2rem; }
.meta { color: var(--muted); font-size: 0.85rem; }
.pane-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.hint { font-size: 0.8rem; color: var(--amber); }

.grid-wrap { overflow: auto; }
table.sched {
  border-collapse: collapse; width: 100%; min-width: 640px;
  table-layout: fixed;
}
table.sched th, table.sched td {
  border: 1px solid var(--line); padding: 0.35rem;
  vertical-align: middle; text-align: center;
}
table.sched thead th {
  background: var(--blue); color: #fff; font-size: 0.9rem;
  position: sticky; top: 0;
}
table.sched th.hours {
  background: var(--blue-2); color: #fff; width: 110px; font-size: 0.78rem;
}
table.sched td.cell {
  height: 58px; cursor: pointer; position: relative;
  font-size: 0.78rem; font-weight: 600; line-height: 1.2;
  transition: filter 0.1s;
}
table.sched td.cell.fixed {
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 5px,
    rgba(31, 78, 121, 0.18) 5px,
    rgba(31, 78, 121, 0.18) 7px
  );
  box-shadow: inset 0 0 0 2px #1f4e79;
}
table.sched td.cell.fixed::after {
  content: "🔒";
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 0.65rem;
  opacity: 0.7;
}
table.sched td.cell:hover { filter: brightness(0.96); outline: 2px solid var(--blue-2); outline-offset: -2px; }
table.sched td.cell .grp {
  display: block; font-weight: 500; font-size: 0.7rem; opacity: 0.85; margin-top: 0.15rem;
}
table.sched td.cell.libre { background: #fafafa !important; color: #9aa5b1; font-weight: 500; }
table.sched td.cell.err { box-shadow: inset 0 0 0 3px var(--red); }
table.sched td.cell.aviso { box-shadow: inset 0 0 0 3px #ef6c00; }
table.sched td.cell.selected { box-shadow: inset 0 0 0 3px var(--blue); }
table.sched td.cell.swap-source { box-shadow: inset 0 0 0 3px #6a1b9a; animation: pulse 1s infinite; }
table.sched td.conflict { background: var(--red-bg) !important; box-shadow: inset 0 0 0 3px var(--red); }
table.sched td.multi { font-size: 0.68rem; }
table.sched tr.recreo-after th, table.sched tr.recreo-after td { border-top: 3px solid #ffb300; }
.recreo-row td {
  background: #fff8e1; font-size: 0.78rem; color: var(--amber); font-weight: 600;
  letter-spacing: 0.04em;
}

.legend { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.7rem; }
.breakdown {
  margin-top: 0.75rem;
  padding: 0.55rem 0.7rem;
  background: #f4f7fb;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.45;
}
.breakdown strong { color: var(--blue); font-size: 0.95rem; }
.apoyo-star { color: var(--amber); font-weight: 700; }
.teacher-item .cat .star, .star { color: #f5a623; }
.lg-chip {
  font-size: 0.72rem; padding: 0.15rem 0.45rem; border-radius: 999px;
  border: 1px solid var(--line); font-weight: 600;
}
.lg.red { color: var(--red); font-size: 0.8rem; }

.issues-list { display: flex; flex-direction: column; gap: 0.4rem; }
.issue {
  border: 1px solid var(--line); border-left-width: 5px;
  border-radius: 8px; padding: 0.55rem 0.75rem; background: #fff;
  font-size: 0.88rem;
}
.issue.error { border-left-color: var(--red); background: var(--red-bg); }
.issue.aviso { border-left-color: #ef6c00; background: var(--amber-bg); }
.issue.info { border-left-color: var(--blue-2); }
.issue .tag {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
  font-weight: 700; color: var(--muted); margin-right: 0.4rem;
}
.empty { color: var(--muted); font-style: italic; }

.group-info { font-size: 0.82rem; color: var(--muted); line-height: 1.45; }

/* menú celda */
.cell-menu {
  position: fixed; z-index: 50; background: #fff;
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
  min-width: 240px; max-width: 320px; max-height: 60vh; overflow: auto;
  padding: 0.45rem;
}
.cell-menu.hidden { display: none; }
.cell-menu h4 { margin: 0.25rem 0.4rem 0.4rem; font-size: 0.8rem; color: var(--muted); }
.cell-menu button {
  display: block; width: 100%; text-align: left; border: none;
  background: transparent; border-radius: 6px; padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}
.cell-menu button:hover { background: #eef3fa; }
.cell-menu button.danger { color: var(--red); }
.cell-menu button strong { font-weight: 650; }
.cell-menu .menu-sep { height: 1px; background: var(--line); margin: 0.35rem 0; }
.cell-menu .grp-tag { color: var(--muted); font-size: 0.75rem; }

/* admin */
.admin-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.8rem;
}
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.8rem;
}
.card h3 { margin: 0 0 0.55rem; font-size: 0.95rem; color: var(--blue); }
.admin-row {
  display: grid; grid-template-columns: 1.2fr 1fr 0.8fr auto; gap: 0.35rem;
  margin-bottom: 0.35rem; align-items: center;
}
.admin-row input, .admin-row select, .card textarea, .filter {
  border: 1px solid var(--line); border-radius: 6px; padding: 0.35rem 0.45rem;
  font-size: 0.84rem; width: 100%;
}
.card textarea { font-family: Consolas, monospace; font-size: 0.78rem; resize: vertical; }
.admin-row .del { width: auto; color: var(--red); padding: 0.25rem 0.45rem; }

.toast {
  position: fixed; bottom: 1.2rem; right: 1.2rem; z-index: 60;
  background: #263238; color: #fff; padding: 0.7rem 1rem;
  border-radius: 8px; font-size: 0.88rem; max-width: 360px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}
.toast.hidden { display: none; }
.toast.error { background: #b71c1c; }
.toast.ok { background: #1b5e20; }

.loading {
  position: fixed; inset: 0; background: rgba(255,255,255,0.72);
  display: flex; flex-direction: column; gap: 0.8rem;
  align-items: center; justify-content: center; z-index: 80;
  font-weight: 650; color: var(--blue);
}
.loading.hidden { display: none; }
.spin {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid #c5d4e4; border-top-color: var(--blue);
  animation: rot 0.8s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.55; } }

code { background: #eef2f7; padding: 0 0.25rem; border-radius: 4px; }

.adjust-bar {
  display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center;
  background: var(--amber-bg); border: 1px solid #f0c000; border-radius: var(--radius);
  padding: 0.55rem 0.8rem; margin-bottom: 0.7rem; font-size: 0.86rem;
}
.adjust-bar.hidden { display: none; }

/* ====== IMPRESIÓN ====== */
@media print {
  .no-print, .tabs, .topbar, .sidebar, .pane-actions, .cell-menu, .toast, .loading { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
  .tab-panel { display: none !important; }
  .tab-panel.active { display: block !important; padding: 0; }
  .content { border: none; padding: 0; }
  table.sched { min-width: 0; }
  table.sched td.cell { height: 52px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.sched thead th, table.sched th.hours { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pane-head h2 { font-size: 1.3rem; }
  @page { landscape; margin: 10mm; }
}
