:root {
  --bg: #f4f1ea;
  --surf: #ffffff;
  --fg: #1c1b18;
  --mut: #6b6a63;
  --line: #e4e0d5;
  --brand: #2f5d4f;
  --brand-fg: #ffffff;
  --danger: #b23b3b;
  --danger-fg: #ffffff;
  --pill: #eef0e8;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

/* --- Login / instalación --- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .sub { margin: 0 0 20px; color: var(--mut); font-size: 13px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--mut); }
.login-card input, .login-card select {
  display: block; width: 100%; margin-top: 6px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px; background: #fff; color: var(--fg);
}
.login-card button, .btn {
  cursor: pointer; border: 0; border-radius: 8px; padding: 10px 16px; font-size: 14px; font-weight: 600;
}
.login-card button { width: 100%; background: var(--brand); color: var(--brand-fg); margin-top: 6px; }
.alert { background: #fbeaea; color: var(--danger); border: 1px solid #f0c9c9; padding: 8px 10px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }

/* --- Cabecera --- */
#hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--surf); border-bottom: 1px solid var(--line);
}
#hdr .titulo { font-weight: 700; font-size: 15px; }
#hdr .r { display: flex; align-items: center; gap: 10px; }
#hdr .byline { color: var(--mut); font-size: 12px; }

.btn-primario { background: var(--brand); color: var(--brand-fg); }
.btn-secundario { background: var(--pill); color: var(--fg); text-decoration: none; display: inline-block; }
.btn-peligro { background: var(--danger); color: var(--danger-fg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }
.admin-main { padding: 20px; max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

.card {
  background: var(--surf); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; }

/* --- Estadísticas --- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surf); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--mut); }
.stat .valor { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--mut); margin-top: 2px; }

/* --- Tabs --- */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tab {
  padding: 7px 14px; border-radius: 999px; background: var(--pill); color: var(--fg);
  border: 0; cursor: pointer; font-size: 13px; font-weight: 600;
}
.tab.activo { background: var(--brand); color: var(--brand-fg); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--mut); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: #faf9f5; }

.tabla-wrap { overflow-x: auto; }
#tabla-solicitudes { min-width: 980px; }
#tabla-solicitudes input, #tabla-solicitudes select {
  width: 100%; box-sizing: border-box; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px;
}
#tabla-solicitudes td { white-space: nowrap; }

.filtros { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.filtros select, .filtros input {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: 12px; color: var(--fg);
}
.filtros .quitar { color: var(--brand); text-decoration: underline; cursor: pointer; font-size: 12px; align-self: center; }

.estado-pill { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; display: inline-block; }
.estado-Pendiente, .estado-pendiente { background: #fbeecb; color: #8a6116; }
.estado-En.curso, .estado-en-curso { background: #d9e8f5; color: #2b5d85; }
.estado-Resuelto, .estado-resuelto { background: #dcefdf; color: #276b3f; }

.locked { opacity: .55; }
.locked-badge { font-size: 11px; color: var(--mut); margin-left: 4px; }

.form-nueva {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; align-items: end;
}
.form-nueva label { font-size: 11px; color: var(--mut); display: flex; flex-direction: column; gap: 4px; }
.form-nueva input, .form-nueva select {
  padding: 8px 9px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
}
.form-nueva button { grid-column: span 6; justify-self: start; }

.msg { font-size: 12px; color: var(--mut); min-height: 1em; margin-top: 8px; }
.msg.error { color: var(--danger); }
.msg.ok { color: #276b3f; }

.form-inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-inline input, .form-inline select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }

.acciones { display: flex; gap: 6px; flex-wrap: wrap; }
.acciones button, .acciones .btn { font-size: 12px; padding: 5px 9px; }

/* --- Modal de historial --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(28,27,24,.45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--surf); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 420px;
  max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 15px; }
.lista-historial { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lista-historial li { font-size: 13px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }

/* --- Departamentos por usuario --- */
.deptos-fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; display: flex; gap: 12px; align-items: center; font-size: 13px; }
.deptos-fieldset legend { font-size: 11px; color: var(--mut); padding: 0 4px; }
.deptos-fieldset label { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.deptos-usuario { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.deptos-usuario label { display: flex; align-items: center; gap: 4px; white-space: nowrap; }

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-nueva { grid-template-columns: repeat(2, 1fr); }
  .form-nueva button { grid-column: span 2; }
}
